Skip to content

Instantly share code, notes, and snippets.

@DavidSSL
Created January 18, 2016 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidSSL/1fcd44e3bc8ccc5c07f5 to your computer and use it in GitHub Desktop.
Save DavidSSL/1fcd44e3bc8ccc5c07f5 to your computer and use it in GitHub Desktop.
class Program
{
// 1 Declaration of a delegate type
public delegate void PersonEatsDelegate();
static void Main()
{
// 3 Instantiation of a delegate (short form)
PersonEatsDelegate personEatsDelegate = Person.Eats;
// 3 Instantiation of a delegate (long form)
PersonEatsDelegate personEatsDelegate1 = new PersonEatsDelegate(Person.Eats);
//4 Invocation of delegate
personEatsDelegate();
}
}
public class Person
{
// 2 Method compatible with PersonEatsDelegate
public static void Eats()
{
Console.WriteLine("The person eats!");
}
public static void Says(string message)
{
// Some implementation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment