Maha

Maha

  • NA
  • 600
  • 70.5k

Different characters of DELEGATE REFERENCE

Oct 5 2015 6:38 PM

You will notice in the 1st example delegate reference is remaining as it is. In the 2nd example same delegate reference "del" has become method. In 3rd example delegate reference "del" has become a parameter.

What I wish to know is whether this is uniquness to delegate reference only.  

Eg1

using System;

delegate void MyDelegate();

class Program

{

    static void Main(string[] args)

    {

        MyDelegate del = new MyDelegate(SayHello);

        del.Invoke();//Delegate reference "del" is remaining as it is

    }

    static void SayHello()

    {

        Console.WriteLine("Hey there!");

    }

}

 Eg2

using System;

delegate void MyDelegate();

 class Program

{

    static void Main(string[] args)

    {

        MyDelegate del = SayHello;

        del();//Delegate reference "del" has become method

    }

    static void SayHello()

    {

        Console.WriteLine("Hey there!");

    }

}

Eg3

using System;

 delegate void MyDelegate();

class Program

{

    static void Main(string[] args)

    {

        MyDelegate del = SayHello;

        Test(del);//Delegate reference "del" has become a parameter

    }

    static void SayHello()

    {

        Console.WriteLine("Hey there!");

    }

    static void Test(MyDelegate del)

    {

        del();

    }

}


Answers (1)