Why can't List = List?

后端 未结 5 1160
予麋鹿
予麋鹿 2020-12-12 03:03

Why won\'t the following code work?

class parent {}
class kid:parent {}

List parents=new List;

It seems obvious t

5条回答
  •  没有蜡笔的小新
    2020-12-12 03:52

    C# 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.

提交回复
热议问题