Delegate Instantiation -Clarification

Posted by nettguy on Stack Overflow See other posts from Stack Overflow or by nettguy
Published on 2010-03-27T07:10:43Z Indexed on 2010/03/27 7:13 UTC
Read the original article Hit count: 352

Filed under:
|

When i have delegate like

public delegate void PrintMe();

(1)
PrintMe a = delegate() { MessageBox.Show("Hello"); };
a();

(2)
PrintMe b = () => { MessageBox.Show("Hello"); };
b();

(3)
PrintMe c = new PrintMe(HelpMe);
c();

static void HelpMe()
{
   MessageBox.Show("Help Me");
}

for (1) and (2) I did not instatntiate the delegate it is directly pointing to anonymous methods.But as in the case of (3) I need to instatntiate the delegate and pass the static method.for case (3) can't i declare like PrintMe c= HelpMe(); ?.How does (1) and (2) work?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about delegates