List常用几种方式

第一种,匹配俩个集合中相同的值

  var listA = new List<int> { 2, 5, 6, 8, 23, 56, 4 };
            var listB = new List<int> { 1, 6, 9, 11, 34, 29, 5, 23, 4 };
           var C= listA.Intersect(listB);
           foreach (var item in C)
           {
               Console.WriteLine(item);
           }
           Console.ReadLine();

第二种,拷贝

 var listA = new List<int> { 2, 5, 6, 8, 23, 56, 4 };
            var listB = new List<int>();

            using (MemoryStream ms = new MemoryStream())
            {
                BinaryFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, listA);
                ms.Position = 0;
                listB = (List<int>)bf.Deserialize(ms);
            }        

参考别人的,具体是谁 我也忘记了

原文地址:https://www.cnblogs.com/LoveAndPeace/p/8133954.html