1 Listl1 = "1,2,3,4,5,6,7,8,9,0".Split(',').ToList(); 2 List l2 = "1,2,3,4,5,6,a,b,c,d,e".Split(',').ToList(); 3 List l3 = "1,2,3".Split(',').ToList(); 4 List l4= "1,2,3".Split(',').ToList(); 5 List l5 = "111,111,2222,3333,4444,5555,6666,6,2,1,54".Split(',').ToList(); 6 //交集 123456 7 List bing = l1.Intersect(l2).ToList(); 8 //并集(不排除重复元素) 1234567890123456abcde 9 List bingNoDistinct = l1.Concat(l2).ToList();10 11 //并集(排除重复元素) 1234567890abcde12 List bingDistinct = l1.Union(l2).ToList();13 14 //及格去重15 List list = l5.Distinct().ToList();16 17 //所有的元素是否全部满足条件 l2集合中是否全部包含l1中的元素18 bool a = l1.All(x => l2.Contains(x));19 20 //集合中是否有满足某些条件的元素 l1集合中是否包含“1”21 bool b = l1.Any(x=>x=="1");22 23 //集合1是否完整包含集合2 l1是否完整包含l324 bool c = l3.All(x => l1.Any(y => x.Equals(y))) ;25 bool d = l3.All(x => l1.Any(y => x==y));26 bool i = l3.All(x => l1.Contains(x));27 28 //两个集合是否相等 l4是否包含l3,并且两个count相等29 bool f = l3.All(x => l4.Contains(x)) && l3.Count == l4.Count;30 31 //根据条件返回集合32 List listCondition = l5.Where(x => x.Length == 2).ToList();
将一个list集合分为等额的子集合
////// 将一个集合分为多个集合 /// ///类 /// 大集合 /// 每一个集合的个数 ///private static List
> SeperateList (List tList,int perInt) { List
> llist = new List
>(); int j = perInt; for (int i = 0; i < tList.Count; i += perInt) { List cList = new List (); cList = tList.Take(j).Skip(i).ToList(); j += perInt; llist.Add(cList); } return llist; }