In C#, the idea of a delegate is that you create an object that refers to a method. This object can be thought of as a sort of pointer to the method.
A delegate type defines a signature for a method (number and type of parameters and return type). Below, StringHandlerDelegate is a delegate type.
A delegate instance is an instance of a delegate type that can refer to one or more methods. Below, del1 is a delegate instance.
Technically, the term delegate refers to the delegate type,
rather than the delegate instance. But to avoid confusion, you could
always refer explicitly to either the delegate instance or the delegate
type.
A delegate type defines a signature for a method (number and type of parameters and return type). Below, StringHandlerDelegate is a delegate type.
1
| private delegate void StringHandlerDelegate( string s); |
1
2
3
4
5
6
7
8
9
| static void Main() { StringHandlerDelegate del1 = Method1; } static void Method1( string text) { Console.WriteLine(text); } |
Sign up here with your email
ConversionConversion EmoticonEmoticon