#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.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: