#1,017 – Delegate Types vs. Delegate Instances

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.

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);

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.

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #1,017 – Delegate Types vs. Delegate Instances

  1. Pingback: Snowden About Spying - The Daily Six Pack; January 24, 2014

  2. Pingback: #1,021 – What Happens to a Delegate’s Return Value | 2,000 Things You Should Know About C#

Leave a comment