KBD

Keith Devens .com

Tuesday, December 2, 2008 Flag waving
This is not The Greatest Song in the World, oh no. This is just a tribute. – Tenacious D
← Slashdot | TurboGears: Python on Rails?Ig Nobel Prizes →

Daily link icon Monday, October 10, 2005

C# 3 language specification

C# 3 Language Specification (.doc), via Michael and the Visual C# Developer Center : Future Versions. C# 3 has lambda expressions with type inference! C# rocks!! And C# 2, which is coming out soon, lets you specify delegate values inline using anonymous methods.

← Slashdot | TurboGears: Python on Rails?Ig Nobel Prizes →

Comments XML gif

James Manning (http://blog.sublogic.com/) wrote:

the inline delegates are of the most value in my experience based on the ability to interact with other local variables. Without that, it's more just avoiding the syntax of putting that delegate logic out to its own method, but once you're interacting with local variables, you have far more power at work. Of course, the compiler has more work to do as it needs to create a new type for you, but it's all hidden and, more importantly, done right by the compiler instead of putting that burden on the developer. Smiley

∴ James Manning | 10-Oct-2005 10:55pm est | http://blog.sublogic.com/ | #8444

Keith (http://keithdevens.com/) wrote:

Are you saying that C# delegates that are specified inline are closures?

Keith | 10-Oct-2005 11:17pm est | http://keithdevens.com/ | #8445

Keith (http://keithdevens.com/) wrote:

Ah, looks like it. Rock! Now to see if I can mutate the data closed by the closure...

Keith | 10-Oct-2005 11:47pm est | http://keithdevens.com/ | #8446

Keith (http://keithdevens.com/) wrote:

Yep, I can:

using System;

class Foo {
    public int amount;
    public Foo(int amount) { this.amount = amount; }
    public Predicate<int> isMoreThan() {
        return delegate(int i) {
            return i > amount++; //inflation
        };
    }
}
class Program {
    static void Main(string[] args) {
        Foo f = new Foo(30);
        Predicate<int> bar = f.isMoreThan();
        Console.WriteLine(bar(31));
        Console.WriteLine(f.amount);
        Console.WriteLine(bar(31));
    }
}

Prints:

True
31
False

Keith | 11-Oct-2005 12:02am est | http://keithdevens.com/ | #8447

Keith (http://keithdevens.com/) wrote:

And another test:

using System;

class Foo {
    public Predicate<int> isMoreThan(int amount) {
        return delegate(int i) {
            return i > amount++; //inflation
        };
    }
}
class Program {
    static void Main(string[] args) {
        Foo f = new Foo();
        Predicate<int> bar = f.isMoreThan(30);
        Console.WriteLine(bar(31));
        Console.WriteLine(bar(31));
    }
}

Prints:

True
False

Keith | 11-Oct-2005 12:06am est | http://keithdevens.com/ | #8448

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

December 2008
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 6 posts

Recent comments XML

new⇒Perl 6 1.0 in March?

Doh, my mistake. I'm aware of the​relation between Parrot and Rakudo​but I'...

Keith: Dec 2, 1:03am

Free image hosting sites

Well, TinyPic has this in its​FAQ:

> Images and videos is in​your accoun...

Keith: Dec 1, 1:13am

Join a NameValueCollection into a querystring in C#

Well with a lamba expression, this​is what I came up​with:

?!code:csharp...

Gustaf Lindqvist: Nov 30, 4:38pm

Why no generic OrderedDictionary?

Check​http://www.codeproject.com/KB/recip​es/GenericOrderedDictionary.aspx?d...

Gabrielk: Nov 27, 6:57am

WhatIsMyIP.com

http://www.thesysteminfo.com is​another good alternate to​whatismp.com... I...

Kripz: Nov 26, 8:51pm

Girls, please don't get breast implants

Actually I think it's sweet when a​man loves a woman whether she's big​or n...

218.186.12.228: Nov 26, 9:40am

Generated in about 0.192s.

(Used 8 db queries)

mobile phone