且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法转换类型为"object {System.Collections.Generic.List< string []>}}"的对象;作为ICollection< object>

更新时间:2021-09-08 07:24:11

在C#4.0之前,泛型不是协变的.如果您不使用C#4.0,则可以像这样完成转换:

Before C# 4.0, generics are not covariant. If you are not using C# 4.0, you can accomplish this cast like this:

List<string[]> list = new List<string[]>();
//...Fill the list...
ICollection<object> collection = list.ConvertAll<object>(item => item as object);