Why won't the following code work?
class parent {}
class kid:parent {}
List<parent> parents=new List<kid>;
It seems obvious to me. What's going on here?
See Question&Answers more detail:osWhy won't the following code work?
class parent {}
class kid:parent {}
List<parent> parents=new List<kid>;
It seems obvious to me. What's going on here?
See Question&Answers more detail:osC# does not currently support covariance.
It's coming in .NET 4.0, however, on interfaces and delegates.
Eric Lippert had a very nice series on this subject on his blog awhile back. Visual Studio Magazine covers it too in a recent article.