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

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA