C# Anonymous methods Edit

Rakesh Kumar Sutar | 21 January 2021 | 1833

Introduction

An anonymous method is a method which doesn't contain any name which is introduced in C# 2.0. Anonymous methods in C# can be defined using the delegate keyword and can be assigned to a variable of delegate type. It is useful when the user wants to create an inline method and also wants to pass parameter in the anonymous method like other methods.

Example

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hello_World
{
    class Program
    {

        public delegate void nameing(string name);

       
        static public void Main()
        {
            nameing p = delegate (string name)
            {
                Console.WriteLine("\n\n\t");
                Console.WriteLine("My Name is {0}",name);
                Console.ReadLine();
            };
            p("Rakesh Kumar Sutar");
        }
    }
}

    



Introduction