C#,vb.net,MVC,Jquery,javascript,jscript,vbscript,html,vb,sharepoint,COM,WPF,WCF,Wwf,Asp,Asp.net,questions & answers,

Latest in Sports

Friday, September 5, 2014

Covariance and Contravariance supported for generic type

Apart from convariance and contravariance available in assignments, parameter types and return types, it is available for genericand delegate types also from C# 4.0 onwards. Covariant types convert from a wider type to narrower type. (e.g., int  to short.).Contravariant types convert from a narrower type to a wider type(For example, from string to object.).


Example:
 Output: Contravariant
 Output: Covariant


No comments:

Post a Comment