problem about generic-variance-Collection of common programming errors


  • Gabe
    c# c#-4.0 type-conversion generic-variance
    Currently I’m preparing a presentation of the new generic variance features in C# for my colleagues. To cut the story short I wrote following lines:IList<Form> formsList = new List<Form> { new Form(), new Form() }; IList<Control> controlsList = formsList;Yes, this is of course not possible, as IList(Of T) is invariant (at least my thought). The compiler tells me that: Cannot implicitly convert type ‘System.Collections.Generic.IList<System.Windows.Forms.Form>’ to ‘System.C

Web site is in building