[My last post seems to have been corrupted by LISTSERV. Reposting here,
trying to have better luck... List admins??]

Mont,

Generally speaking, you always have to use a method delegate to pass a
"method" as a parameter to a function. To make the whole syntax easier,
the C# 2.0 compiler can infer the delegate type you are using in an
expression from the called method signature, in addition to the one of
the method you are passing as a parameter. Here's a short example which
I hope would make it clearer:

// A simple delegate
delegate void TestDelegate(int a);

// A simple method that would match TestDelegate signature
void MethodToPass(int firstParameter)
{
}

// A method that would accept a method with a TestDelegate signature as
its parameter
void TestCompilerInference(TestDelegate myMethod)
{
}

Now suppose you have to call the aforementioned TestCompilerInference()
method, passing a delegate to the MethodToPass() method. You have two
possible solutions for this one; the standard method:

TestCompilerInference(new TestDelegate(MethodToPass));

And the following one:

TestCompilerInference(MethodToPass);

Note that both ways will produce the same IL code; in the second case
the C# 2.0 compiler will infer the right delegate type from the
signatures of the methods you are using.
Hope this helps.

--
Efran Cobisi
http://www.cobisi.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to