Created
January 18, 2016 18:03
-
-
Save DavidSSL/1fcd44e3bc8ccc5c07f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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