O'Reilly logo

Pro C# 2010 and the .NET 4 Platform, Fifth Edition by Andrew Troelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

11.8. Understanding Generic Delegates

Recall from the previous chapter that C# does allow you to define generic delegate types. For example, assume you wish to define a delegate type that can call any method returning void and receiving a single parameter. If the argument in question may differ, you could model this using a type parameter. To illustrate, consider the following code within a new Console Application named GenericDelegate:

namespace GenericDelegate
{
  // This generic delegate can call any method
  // returning void and taking a single type parameter.
  public delegate void MyGenericDelegate<T>(T arg);
class Program { static void Main(string[] args) { Console.WriteLine("***** Generic Delegates *****\n"); // Register targets. MyGenericDelegate<string> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required