比较两个集合是否相等,而不论它们中项的顺序如何
collection1 = {1, 2, 3, 4};collection2 = {2, 4, 1, 3};collection1 == collection2; // true
if (collection1.Count != collection2.Count) return false; // the collections are not equalforeach (Item item in collection1){ if (!collection2.Contains(item)) return false; // the collections are not equal}foreach (Item item in collection2){ if (!collection1.Contains(item)) return false; // the collections are not equal}return true; // the collections are equal
collection1 = {1, 2, 3, 3, 4}collection2 = {1, 2, 2, 3, 4}
注:
冉冉说
拉风的咖菲猫
相关分类