I am trying to do this:
List<Parent> test = new List<Child>();
The complete code of my class is this:
class Program
{
public static void Main(string[] args)
{
List<Parent> test = new List<Child>();
test.Add(new Child());
test.Add(new AnotherChild());
}
}
class Parent { }
class Child : Parent { }
class AnotherChild : Parent { }
Can someebody please explian me why this gives me this error:
Error 2 Cannot convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List' d:\personal\documents\visual studio 2010\Projects\ConsoleApplication3\ConsoleApplication3\Program.cs 20 24 ConsoleApplication3
And why does this work?
Parent[] test = new Child[10];
List<Parent> result = test.ToList();
Thanks :)
-- Right:
Now I know why: List is compiled to List`1
and List to List`2
. And they have no relationship.