连接具有LINQ名单 [英] Concatenate lists with LINQ

查看:109
本文介绍了连接具有LINQ名单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以连接一列表<名单< T>> 列表< T> 与在某种程度上的单一操作,这是不可怕的慢,即:

 列表<名单< INT>> listOfLists =新的List<名单,LT; INT>>(); 
名单,LT; INT> concatenatedList = listOfLists.Something ...




解决方案

  listOfLists.SelectMany(L =→1); 



全系列:

 列表与LT; INT> concatenatedList = listOfLists.SelectMany(L =→1).ToList(); 


Is it possible to concatenate a List<List<T>> into a List<T> with a single operation in a way which isn't horrible slow, i.e:

List<List<int>> listOfLists = new List<List<int>>();
List<int> concatenatedList = listOfLists.Something...

?

解决方案

listOfLists.SelectMany( l => l );

full line:

List<int> concatenatedList = listOfLists.SelectMany( l => l ).ToList();

这篇关于连接具有LINQ名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆