Variant delegates C# with Example



Variant delegates C# with Example

Delegates may have variant type parameters. 
delegate void Action(T t); //  T  is an  input 
delegate T Func(); //  T  is an  output 
delegate T2 Func(); // T1 is an input, T2 is an output 
This follows from the Liskov Substitution Principle, which states (among other things) that a method D can be 
considered more derived than a method B if: 
D has an equal or more derived return type than B 
D has equal or more general corresponding parameter types than B 
Therefore the following assignments are all type safe: 
Func original = SomeMethod; 
Func d1 = original; 
Func d2 = original; 
Func d3 = original; 
 

0 Comment's

Comment Form

Submit Comment