Could someone explain what anonymous methods are in C# (in simplistic terms) and provide examples in possible please
Could someone explain what anonymous methods are in C# (in simplistic terms) and provide
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Anonymous methods were introduced into C# 2 as a way of creating delegate instances without having to write a separate method. They can capture local variables within the enclosing method, making them a form of closure.
An anonymous method looks something like:
and must be converted to a specific delegate type, e.g. via assignment:
… or subscribing an event handler:
For more information, see:
Note that lamdba expressions in C# 3 have almost completely replaced anonymous methods (although they’re still entirely valid of course). Anonymous methods and lambda expressions are collectively described as anonymous functions.