Content feed Comments Feed

The Official ASATO Site

Hi, welcome to my blog. ASP,asp.net,Health,Javascript,JQUERY

what is a delegate?
a delegate is a type that defines a method signature, and can be associated with any method with a compatible signature. (MSDN)

Declaring a delegate:
public delegate int PerformCalculation(int x, int y);
or
public delegate void TestDelegate(string message);

Demo:
using System;
public delegate void TestDelegate(string message); //Declare the delegate
class Test
{
  public static void Display(string message)
  {
    Console.WriteLine("The string entered is : " + message);
  }
  static void Main()
  {
    TestDelegate t = new TestDelegate(Display); //Instantiate the delegate
    Console.WriteLine("Please enter a string");
    string message = Console.ReadLine();
    t(message); //Invoke the delegate
    Console.ReadLine();
  }
}

5 Responses to “what is a delegate? how working with delegates in c sharp?”

  1. Hello, I can’t understand how to add your blog in my rss reader
    ————————
    sponsor: http://xabul.ru/

  2. admin says:

    and i do not see your website in my IE!

  3. essergieT says:

    I`m going to…
    —————————————
    signature: http://wksc.ac.th/moodle/user/view.php?id=229&course=1&metka=ge5he8hgp

  4. usakifekisy says:

    I can’t believe it!
    —————————————
    signature: buy acyclovir seg6se98i

Leave a Reply