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.7. Understanding Delegate Covariance

As you may have noticed, each of the delegates created thus far point to methods returning simple numerical data types (or void). However, assume you have a new Console Application named DelegateCovariance that defines a delegate type that can point to methods returning a custom class type (be sure to include your Car class definition in this new project):

// Define a delegate type pointing to methods that return Car objects.
public delegate Car ObtainCarDelegate();

Of course, you would be able to define a target for the delegate as expected:

namespace DelegateCovariance { class Program { // Define a delegate type pointing to methods that return Car object. public delegate Car ObtainCarDelegate(); static ...

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