Example of Anonymous methods in C#

Anonymous methods in C# are like regular methods nut does not contain any name. Anonymous methods are just like regular methods  and uses the delegate keyword and does not need a name , parameter or return type.

Example of Anonymous methods in C#

Below is a sample code snippet demonstrating the usage of the anonymous types in C#

using System;
using System.Collections.Generic;

namespace AbundantCodeConsoleApp
{
    internal class Program
    {
        private delegate void result();

        private static void Main(string[] args)
        {
            result p = delegate
            {
                Console.WriteLine(3 + 5);
            };
            p();

            Console.ReadLine();
        }
    }
}

Leave Your Comment

Liked this content?. Please spread the word :)