|
From: | Thong (Tum) Nguyen |
Subject: | RE: [DotGNU].net futures |
Date: | Sat, 23 Aug 2003 12:16:11 +1200 |
I noticed that too. I wonder if they’ll allow explicitly casting between two different but compatible delegates.
e.g.
delegate void D1(string s); delegate void D2(string s);
D1 d1; D2 d2
d1 = delegate(string s) { }; d2 = (D2)d1;
Of course you could just use:
d2 = delegate(string s) { d1(s) };
An implicit conversion without a cast would be naughty but seeing as they’re relaxing the requirement to explicitly construct the delegate from its type it makes sense to allow casting from between compatible delegates (even if the cast is really just a disguised proxy anonymous method). ^Tum -----Original Message-----
I've noticed several people referencing this summary of new C# features over on GDN lately in response to the recent flurry of discussion on delegates.
Readers should be aware that the syntax for anonymous methods has changed somewhat since that whitepaper was posted. Specifically, one no longer uses the name of the delegate type when declaring the anonymous method.
For example, this code excerpted from the aforementioned whitepaper:
public MyForm()
would now be written like this:
public MyForm()
It's also worth noting that this example illustrates two new features. The obvious one is the anonymous method feature. The more subtle feature is the fact that Whidbey C# relaxes the requirement to explicitly instantiate a delegate type. For example, consider the first example (not using anonymous methods):
public MyForm()
In whidbey C#, you are allowed to (but not required to) omit the "new T" and just do the assignment:
public MyForm()
Shades of C function pointers!
Of course, readers should be aware that the moment after I click the submit button all of this might change yet again (unlikely but not impossible).
As always, consult the actual bits (which can be had at PDC in October). --- --- |
[Prev in Thread] | Current Thread | [Next in Thread] |