#1,017 – Delegate Types vs. Delegate Instances
January 23, 2014 2 Comments
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.
private delegate void StringHandlerDelegate(string s);
A delegate instance is an instance of a delegate type that can refer to one or more methods. Below, del1 is a delegate instance.
static void Main() { StringHandlerDelegate del1 = Method1; } static void Method1(string text) { Console.WriteLine(text); }
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.
Pingback: Snowden About Spying - The Daily Six Pack; January 24, 2014
Pingback: #1,021 – What Happens to a Delegate’s Return Value | 2,000 Things You Should Know About C#