C# program to demonstrate the example of an array of delegates

C# program to demonstrate the example of an array of delegates I am very interested to talk to you about this article. The reason is that this article contains very interesting information. Let’s go to this article

C# program to demonstrate the example of an array of delegates

C# program to demonstrate the example of an array of delegates

//C# program to demonstrate an array of delegates.

using System;

delegate void MyDel();

class Sample
{ 
    static void Method1()
    {
        Console.WriteLine("\tMethod1 called");
    }

    static void Method2()
    {
        Console.WriteLine("\tMethod2 called");
    }

    static void Method3()
    {
        Console.WriteLine("\tMethod3 called");
    }

    static void Main()
    {
        MyDel[] del = new MyDel[3];


        del[0] = Method1;
        del[1] = Method2;
        del[2] = Method3;

        Console.WriteLine("Invoke methods using delegates:");
        for (int i = 0; i < 3; i++)
        {
            del[i]();
        }
    }
}
Invoke methods using delegates:
        Method1 called
        Method2 called
        Method3 called
Press any key to continue . . .

Final Words

We learned some interesting information through the article C# program to demonstrate the example of an array of delegates. Also if you have any doubts about this article you can report your doubts as a comment box. Thanks

Hi, I'm Selva a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Deekshi. Here, I post about programming to help developers.

Share on:

Leave a Comment