G
Guest
I have a collection class that contains objects of the type of another class
call it Class1, that I have created. The constructor for Class1 takes two integers
These go on to be fields of the class, 'Low' and 'High'
I want the following to happen
MyCollection cn = new MyCollection()
cn.Add(new Class1(1, 2))
cn.Add(new Class1(1, 3))
cn.Add(new Class1(1, 4))
//then I want this to be true
if(cn.Contains(new Class1(1, 3))
//object with Low = 1, High = 3 has been foun
Of course they are reference types, so they are no
the same thing, and it returns false. But in my mind the
are, so I want to be able to program it so that it knows this
I'm pretty sure from the documentation that it is possibl
to determine this using some fancy hash-table based method
and I'd rather do this than a loop
although it is a bit of a minefield and I'm fairly new to this
What do I do - override Class1.Equals()? Overrid
MyCollection.Contains()? Implement IComparable
All of these
I don't need the objects to be ordered, although I do nee
them to behave like value types, but only with regard to th
Contains method
Can anyone give me a starter
Thank
call it Class1, that I have created. The constructor for Class1 takes two integers
These go on to be fields of the class, 'Low' and 'High'
I want the following to happen
MyCollection cn = new MyCollection()
cn.Add(new Class1(1, 2))
cn.Add(new Class1(1, 3))
cn.Add(new Class1(1, 4))
//then I want this to be true
if(cn.Contains(new Class1(1, 3))
//object with Low = 1, High = 3 has been foun
Of course they are reference types, so they are no
the same thing, and it returns false. But in my mind the
are, so I want to be able to program it so that it knows this
I'm pretty sure from the documentation that it is possibl
to determine this using some fancy hash-table based method
and I'd rather do this than a loop
although it is a bit of a minefield and I'm fairly new to this
What do I do - override Class1.Equals()? Overrid
MyCollection.Contains()? Implement IComparable
All of these
I don't need the objects to be ordered, although I do nee
them to behave like value types, but only with regard to th
Contains method
Can anyone give me a starter
Thank