I would like to create my own extending class of int classes. Is it possible? I need an int array, which can be added by the "+" operator to another array (each element is added to each) and compared with "==", so it can (hopefully) be used as a key in the dictionary.
The fact is that I do not want to implement the entire IList interface for my new class, but only add these two statements to the existing array class.
I am trying to do something like this:
class MyArray : Array<int>
But it does not work that way, obviously;).
Sorry if I'm unclear, but I'm looking for a solution in a few hours ...
UPDATE:
I tried something like this:
class Zmienne : IEquatable<Zmienne> { public int[] x; public Zmienne(int ilosc) { x = new int[ilosc]; } public override bool Equals(object obj) { if (obj == null || GetType() != obj.GetType()) { return false; } return base.Equals((Zmienne)obj); } public bool Equals(Zmienne drugie) { if (x.Length != drugie.x.Length) return false; else { for (int i = 0; i < x.Length; i++) { if (x[i] != drugie.x[i]) return false; } } return true; } public override int GetHashCode() { int hash = x[0].GetHashCode(); for (int i = 1; i < x.Length; i++) hash = hash ^ x[i].GetHashCode(); return hash; } }
Then use it as follows:
Zmienne tab1 = new Zmienne(2); Zmienne tab2 = new Zmienne(2); tab1.x[0] = 1; tab1.x[1] = 1; tab2.x[0] = 1; tab2.x[1] = 1; if (tab1 == tab2) Console.WriteLine("Works!");
And no effect. Unfortunately, I am not very well versed in interfaces and overriding methods :( Regarding the reason, I am trying to do this. I have some equations like:
x1 + x2 = 0.45
x1 + x4 = 0.2
x2 + x4 = 0.11
There are many more, and I need, for example, to add the first equation to the second and find all the others to find out if there is something that matches the combination of x'es, which leads to the addition.
Maybe I'll go in the completely wrong direction?