Javatpoint Logo
Javatpoint Logo

C# Delegates Covariance

C# Delegate Covariance allows us to call a method that has derived return type of the delegate signature return type.

It means we can call a method that returns parent or child class object.

Here, we are creating two examples. First example calls a method that returns a parent or derived class object.

C# Delegate Covariance Example 1


This is MethodA
This is MethodB

C# Delegate Covariance Example 2

In this example, we are calling a method that does not return derived object as specified in delegate signature. Let's see what happen, if we do this.


DelegateCoveriance.cs(25,31): error CS0407: 
'CSharpFeatures.C CSharpFeatures.DelegateCoveriance.MethodC()' has the wrong return type

Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


B.Tech / MCA