Casting a generic collection to base type

前端 未结 6 915
情歌与酒
情歌与酒 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

    You can cast each element into new iterator:

    var collectionOfBase = (collectionOfDerived as IEnumerable).Cast();
    

提交回复
热议问题