Anonymous Methods



What are Anonymous Methods in C#?

An anonymous method is a method without a name as the name suggestes. This type of methods can be defined using the delegate keyword. It can be assigned to a variable of delegate type.

Anonymous method provides the same functionality as lambda expression, except that it allows us to omit parameter list.

Example:

using System;  
namespace AnonymousMethod
{  
    class AnonymousMethodClass
    {  
        public delegate void AnonymousFunction();  
        static void Main(string[] args)  
        {  
            AnonymousFunction func = delegate () {  
                Console.WriteLine("This is anonymous function");  
            };  
            func();  
        }  
    }  
}  

Output:

This is anonymous function

0 Comment's

Comment Form

Submit Comment