Describe contra-variance and covariance
Briefly describe contra-variance and covariance in .NET Framework 4.0 and give an example for both?
Expert
In .NET 4.0, the CLR supports contra-variance and covariance of kind in general interfaces and delegates. Covariance allow to cast a generic kind to its base types, that is, we can allot a instance of type IEnumerable<Tl> to a variable of type IEnumerable<T2> where, T1 receives from T2. Such as:
Contravariance permits us to allot a variable of Action<base> to a variable of type Action<derived>. Like:
IEnumerable<string> str1= new List<string> (); IEnumerable<object> str2= str1; IComparer<object> obj1 = GetComparer() IComparer<string> obj2 = obj1
.NET framework 4.0 uses a number of language keywords ‘in and out’ to interpret covariance and contra-variance. ‘Out’ is for covariance, whereas ‘in’ is used for contra-variance.
Variance can be related only to reference types, generic delegates and generic interfaces. These cannot be applied to generic types and value types.
Distinguish the terms ADO.NET Dataset and an ADO Recordset?
Write differences between Int32 and Int.
Define is IIS and also explains its uses?
Specify the function of CheckState property of the CheckBox control?
State the use of DropDownStyle property of the ComboBox control?
What setting should be added in a configuration file to reject the particular user from accessing secured resources?
Differentiate between a ContextMenuStrip control and a MenuStrip control?
How can we programmatically place a cursor on the given line or on the character in a RichTextBox control in the C#?
State some of the different ways in order to pass parameters to the server?
Explain two properties of GridView control which specifies to turn on paging and sorting.
18,76,764
1937572 Asked
3,689
Active Tutors
1434216
Questions Answered
Start Excelling in your courses, Ask an Expert and get answers for your homework and assignments!!