Casting a generic collection to base type

前端 未结 6 922
情歌与酒
情歌与酒 2020-12-03 22:46

I\'ve got an IList that I want to cast to ICollection but when I attempt an explicit cast, I get null

6条回答
  •  南笙
    南笙 (楼主)
    2020-12-03 23:50

    This is called co-variance and while not currently supported with generics in .net, it will be added in the 4.0 framework (along with the opposite which is contra-variance).

    This excellent video from PDC 2008 is session on C# futures given by Anders Hejlsberg:

    http://channel9.msdn.com/pdc2008/TL16/

提交回复
热议问题