I have a private readonly
list of LinkLabel
s (IList
). I later add LinkLabel
s to this list and add those
With VS 2008, I am not getting this warning. This must be new to .NET 4.0.
Clarification: according to Sam Mackrill it's Resharper who displays a warning.
The C# compiler does not know that AddRange
will not modify the array passed to it. Since AddRange
has a parameter of type Control[]
, it could in theory try to assign a TextBox
to the array, which would be perfectly correct for a true array of Control
, but the array is in reality an array of LinkLabels
and will not accept such an assignment.
Making arrays co-variant in c# was a bad decision of Microsoft. While it might seem a good idea to be able to assign an array of a derived type to an array of a base type in the first place, this can lead to runtime errors!