Are there any value type collection in C#? -
are there collections value type semantics in c#? set1 equals set2 if contain same structs/primitives? maybe in same order.
hashset pretty close, ==
doesn't compare values in collections. setequals
return true if contain same values. however, order doesn't factor in. can use sequenceequal
if order important.
static void main(string[] args) { hashset<int> set1 = new hashset<int> { 1, 2, 3 }; hashset<int> set2 = new hashset<int> { 2, 1, 3 }; hashset<int> set3 = new hashset<int> { 1, 2, 3 }; console.writeline(set1.setequals(set2)); // true console.writeline(set1.sequenceequal<int>(set2)); // false console.writeline(set1.sequenceequal<int>(set3)); // true }
Comments
Post a Comment