Created
January 7, 2018 22:32
-
-
Save luisdeol/9f481816a0a51babb6515594a04dda6d to your computer and use it in GitHub Desktop.
Understanding Delegates
This file contains hidden or 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
using System; | |
namespace create_implement_events_callbacks | |
{ | |
class Program | |
{ | |
public delegate int Calculate(int x, int y); | |
public static int Add(int x, int y) | |
{ | |
return x + y; | |
} | |
public static int Multiply(int x, int y) | |
{ | |
return x * y; | |
} | |
static void Main(string[] args) | |
{ | |
Calculate calc = Add; | |
Console.WriteLine(calc(3, 4)); | |
calc = Multiply; | |
Console.WriteLine(calc(3, 4)); | |
Console.ReadKey(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment