Calling Member Function using delegates in C#

Calling Member Function using delegates in C#

In this article, we will figure out how to call a part work using delegates in C#? It is like the static part of work calls.

We can likewise call a part capacity of a class using delegates. It is like static capacity calls, here we need to pass part work using an article on the making of representative.

Program:

using System;
using System.Collections;

public delegate void myDelegates();
class Sample
{
    public void fun()
    {
        Console.WriteLine("Call a member function using delegate");
    }
}


class Program
{
    static void Main()
    {
        Sample S = new Sample();
        myDelegates del = new myDelegates(S.fun);
        del();
    }
}

Output:

    Call a member function using delegate

In above example, we made the class Sample, Sample class contains a part work name fun(). And afterward, we made another class Program than contains Main() work. Here, we made agent reference and passed part work using Sample class object.

Recent Posts

error: Alert: Content is protected!!