1. 可以用查询结果的 ToList()方法
2. 示例代码如下:
using System
using System.Collections.Generic
using System.Linq
using System.Text
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int[] arr = { 3, 4, 5, 6, 7, 8, 11 }
List<int> evenList
//找出arr中的偶数放入 一个evenList里
var result = from v in arr where v % 2 == 0 select v
evenList = result.ToList()
//显示evenList的结果
foreach (var v in evenList)
Console.Write("{0} ", v)
Console.WriteLine()
Console.ReadKey()
}
}
}
3. 运行结果如下
简单写了一下:List<int[]>li = new List<int[]>()
for(int i = 0i <1000000i++)
{
if (i % 2 == 0)
{
int[] q = new int[] { 0, 1, 2, 3, 4, 5, 6 }
li.Add(q)
}
else
{
int[] q = new int[] {8, 0, 1, 2, 3, 4, 5, 6 }
li.Add(q)
}
}
var res = (from q in li where q[0] != 8 select q).ToList()//核心
using System.Linqproplist.Aggregate((currentList, nextList) =>currentList.Concat(nextList).ToList()).Aggregate((current, next) =>current + "," + next)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)