Thursday, 17 January 2019

What is an Anonymous Methods?

Anonymous methods are inline code blocks which have no name. Creating anonymous methods is essentially a way to pass a code block as a delegate parameter. 

void StartThread() { System.Threading.Thread t1 = new System.Threading.Thread (delegate() { System.Console.Write("Hello, "); System.Console.WriteLine("World!"); }); t1.Start(); }

The scope of the parameters of an anonymous method is the anonymous-method-block.

It is an error to have a jump statement, such as gotobreak, or continue, inside the anonymous method block if the target is outside the block. It is also an error to have a jump statement, such as gotobreak, or continue, outside the anonymous method block if the target is inside the block.

An anonymous method cannot access the inref or out parameters of an outer scope.
No unsafe code can be accessed within the anonymous-method-block.
Anonymous methods are not allowed on the left side of the is operator.

No comments:

Post a Comment