Ah, I see where you were going now Plater. :)
One method to fix your new problem would be Platers suggestion, which should work well.
Alternatively, you could also thinly wrap List<int> and override the Equals() and GetHashCode() methods. I've chucked together a bit of code for you:
- public class MyIntCollection : List<int>
-
{
-
public override bool Equals(object obj)
-
{
-
MyIntCollection collection2 = (MyIntCollection)obj;
-
-
if (collection2.Count != this.Count) return false;
-
for (int i = 0; i < this.Count; i++)
-
{
-
if (this[i] != collection2[i]) return false;
-
}
-
return true;
-
}
-
-
public override int GetHashCode()
-
{
-
int hashCode = 0;
-
for (int i = 0; i < this.Count; i++)
-
{
-
hashCode = hashCode ^ this[i];
-
}
-
return hashCode;
-
}
-
}
You could then use this class in place of your List<int>. like so:
-
Dictionary<List<int>, Polynomial> A = new Dictionary<List<int>, Polynomial>();
-
// initialize A with last column.
-
for (int r = 0; r < n; ++r)
-
{
-
MyIntCollection PKey = new MyIntCollection();
-
Pkey.Add(r);
-
A.Add(Pkey, m.GetElement(r, n - 1));
-
}
Using this method, two seperate lists containing the same numbers (in the same sequence) are considered equal, regardless of whether or not they are the same reference. Trying to add two different MyIntCollection objects containing the same sequence of numbers to the dictionary fails.
You can modify the code of Equals() to determine whether two MyIntCollections are equal to suit your requirements. GetHashCode() is required by the Dictionary class to ensure that keys are unique. It must return the same value for objects where Equals() returns true. You can look these up on MSDN for more info if required.