一个集合全包含判断,求最简单的代码~
List<int> a1 = {1,2,3};List<int> a2 = {1,2,3,4,5,6,7};
如果a1全包含在a2中则返回true;
求最简单的代码 --------------------编程问答--------------------
List<int> a1 = new List<int>(){ 1, 2, 9 };--------------------编程问答--------------------
List<int> a2 = new List<int>() { 1, 2, 3, 4, 5, 6, 7 };
if (a1.Intersect(a2).Count() == a1.Count())
{
//包含
}
--------------------编程问答-------------------- if (a1.Except(a2).Count() == 0) --------------------编程问答-------------------- 或者
public static bool ContainsAll<T>(List<T> container, List<T> subset){
return container.Intersect(subset).Count() == subset.Count;
}
a1.All(x => a2.Contains(x)) //这个最容易看懂:a1中全部(all)元素都包括在(contains)a2中 --------------------编程问答-------------------- 上边都是高手,学习了!
补充:.NET技术 , C#