The .Contains
works on the .Equals
method. By default, the .Equals
method returns only true
, if the two instances (references) are the same.
A possible way to solve this - if the number of factors are fixed - is using a Tuple<int,int>
. You can define the Reverse
method on a `Tuple class with:
public static class Foo {
public static Tuple<T2,T1> Reverse<T1,T2> (this Tuple<T1,T2> tuple) {
return new Tuple<T2,T1>(tuple.Item2,tuple.Item1);
}
}
And then call it simply with:
Tuple<int,int> t = new Tuple<int,int>(3,5);
Tuple<int,int> t2 = t.Reverse();
If not, you could define a wrapper class, that performs the equality check as described here.
Or another alternative, is to provide an equality checker yourself in the .Contains
method as described by @xanatos answer.
Demo:
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> var t1 = new Tuple<int,int>(3,2);
csharp> var t2 = new Tuple<int,int>(3,2);
csharp> t1.Equals(t2);
true
csharp> int[] t1 = new int[] {3,2};
csharp> int[] t2 = new int[] {3,2};
csharp> t1.Equals(t2);
false