linq

using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp29
{
    class Program
    {
        static void Main(string[] args)
        {

            var t = new List<int>
            {
               1,
               2,
               3,
               4,
            };

           var s= t.Aggregate((a, b) => (a + b));//10

            var st = t.Sum();//10

            var pp = t.Average();//2.5

            var ts = t.Cast<object>();//转换

            var person1 = new List<string>
            {
                "test",
                "tom",
                "jerry",
                "jimi"
            };
            var person2 = new List<string>
            {
                "test1",
                "tom",
                "jerry",
                "jimi"
            };

            var se = person1.Except(person2).ToList();//差集
            var se1 = person1.Intersect(person2).ToList();//并集

            var se2 = person1.Concat(person2);

            IEnumerable<int> obj = Enumerable.Repeat(100, 10);//重复10次100


            Console.ReadKey();



        }
    }
}

  

posted @ 2021-07-13 15:06  面无表情的石头  阅读(61)  评论(0)    收藏  举报