c#使用 linq 怎么给list赋值

c#使用 linq 怎么给list赋值,第1张

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.Linq

proplist.Aggregate((currentList, nextList) =>currentList.Concat(nextList).ToList()).Aggregate((current, next) =>current + "," + next)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11404607.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存