- List<string> list1 = new List<string>() { "0", "1" };
- List<string> list2 = new List<string>() { "1", "0" };
如何比较上面两个集合 list1,list2, 它们是否相等
给出的条件是: 只要其元素的个数, 内容相等, 就算相等, 而不管元素的排序, 索引值是否相等.
比如 { "0", "1" }与 { "1", "0" } 算是相等的,{ "4", "5" }与{ "5", "4" } 也是相等的
方法:
var isEquall = list1.Count == list2.Count && list1.OrderBy(x => x).Zip(list2.OrderBy(x => x), (x, y) => x == y).All(x => x == true);
如果为 true 则相等, false 则不相等
来源: http://www.bubuko.com/infodetail-2557430.html