n C#, you typically invoke a delegate by using the variable referring to the delegate instance as if it were a method.
For example, in the code below, the variable del1 is a delegate instance and you invoke it by using del1 as if it was a method.
Alternatively, you can call the Invoke method on the delegate instance. This does exactly the same thing as the example above.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| static void Method1(string text){ Console.WriteLine(text);}static void Main(string[] args){ StringHandlerDelegate del1 = Method1; // Invoke the delegate instance del1("Invoked through delegate"); Console.ReadLine();} |
1
2
| // Invocation, method #2del1.Invoke("Also invoked thru delegate"); |
Sign up here with your email
ConversionConversion EmoticonEmoticon