【发布时间】:2022-01-13 12:46:42
【问题描述】:
我想将这个列表合并或合并为一个列表。 如何正确连接此列表?
编译器错误消息:CS0266:无法将类型“System.Collections.Generic.IEnumerable
List<Dictionary<string, object>> result1 = process1(); // OK
List<Dictionary<string, object>> result2 = process2(); // OK
List<Dictionary<string, object>> result3 = process3(); // OK
List<Dictionary<string, object>> result4 = process4(); // OK
List<Dictionary<string, object>> result5 = process5(); // OK
var d1 = result1;
if(result2 != null){
d1 = d1.Concat(result2).ToList();
}
if(result3 != null){
d1 = d1.Concat(result3);
}
if(result4 != null){
d1 = d1.Concat(result4);
}
if(result5 != null){
d1 = d1.Concat(result5);
}
【问题讨论】:
-
你需要在每个
Concat()之后使用.ToList() -
Concat<T>返回一个IEnumerable<T>而d1显然是一个List<T>
标签: c# list dictionary merge concatenation