Covariance and Contra-variance
What is covariance and contra-variance in .NET Framework 4.0 with example for each.
Expert
In .NET 4.0, CLR supports contra variance and covariance of types in the generic interfaces and delegates.
Covariance allows you to cast the generic type to its base types, that is, instance of type IEnumerable<Tl> can be assigned to a variable of type IEnumerable<T2> where, T1 derives from T2. For example, IEnumerable<string> str1= new List<string> (); IEnumerable<object> str2= str1;
Contravariance permits you to assign a variable of Action<base> to a variable of type Action<derived>. For illustration, IComparer<object> obj1 = GetComparer() IComparer<string> obj2 = obj1;
.NET framework 4.0 uses some language keywords (out and in) to annotate contra- variance and covariance. “Out” is used for covariance, while “in” is used for contra-variance. Variance is applied only to generic interfaces, reference types and generic delegates. These cannot be applied to generic types and value types.
Describe in brief regarding the Visual basic.NET culture?
What will happen if the ASP.NET server control with the event-handling routines is absent from its definition?
In what way we can display the icon during runtime on a StatusStrip control?
What is the role of the DynamicPopulateExtender control?
Explain how is docking different from the anchoring?
Which classes are used to handle standard menu in the MenuStrip control.
What do you mean by the term MISL CODE? Describe in brief.
In what way we can display the icon or bitmap image on a Button control?
The information, like role management membership, profile, and Web parts personalization is stored in which database?
State the values that can be allocated to the DialogResult property of the Button control?
18,76,764
1945466 Asked
3,689
Active Tutors
1446009
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!