對於你的情況,請儘量使用LINQ Concat
:
這導致List<string[]>
var newlist = coords_list
.Concat(outer_plf_list)
.Concat(planet_start_plf_list)
.Concat(planet_plf_list)
或者,如果您需要List<string>
,請執行以下操作:
var newlist = coords_list
.Concat(outer_plf_list)
.Concat(planet_start_plf_list)
.Concat(planet_plf_list)
.SelectMany(x => x)
.ToList();
你也可以使用AddRange
作爲一種替代方案:
var newlist = new List<string[]>();
newlist.AddRange(coords_list);
newlist.AddRange(outer_plf_list);
newlist.AddRange(planet_start_plf_list);
newlist.AddRange(planet_plf_list);
如果你有List<List<List<string>>>
而不是List<string[]>
不同string[]
大小,你可以使用SelectMany
拉平List<List<List<string>>>
到List<List<string>>
來源
2016-02-27 15:48:55
Ian
http://stackoverflow.com/questions/4493858/elegant-way-to-combine-multiple-collections-of-elements或http://stackoverflow.com/questions/4734556/concatenate-lists-與-LINQ。 –
@EugenePodskal感謝您的鏈接。 –
@RyanWalkowski所以,你想要的是一個,單,'列表'是嗎?或者它是'List ' –
Ian