G
Guest
Hello,
I have this class:
public class TestClass
{
private string testData = "";
public string TestData
{
get { return this.testData; }
set { this.testData = value; }
}
//public override bool Equals(object obj)
//{
// return this.testData.Equals(obj);
//}
//public override int GetHashCode()
//{
// return this.testData.GetHashCode();
//}
}
and I use it like this:
static void Main(string[] args)
{
TestClass test = new TestClass();
ArrayList ary = new ArrayList();
test.TestData = "test data";
ary.Add(test);
Trace.WriteLine(((TestClass)ary[0]).TestData);
Debug.Assert(ary.Contains(test), "Asserting the collection
contains <test>.");
}
With the *Equals* override commented everything works fine: the trace writes
the "test data" string and the assert is quiet.
Could somebody please tell me why if only the *Equals* override is
uncommented the trace still works fine but the assert fails ?
Note: commenting/uncommenting the GetHashCode() doesn't seem to make any
difference.
Thanks in advance...
I have this class:
public class TestClass
{
private string testData = "";
public string TestData
{
get { return this.testData; }
set { this.testData = value; }
}
//public override bool Equals(object obj)
//{
// return this.testData.Equals(obj);
//}
//public override int GetHashCode()
//{
// return this.testData.GetHashCode();
//}
}
and I use it like this:
static void Main(string[] args)
{
TestClass test = new TestClass();
ArrayList ary = new ArrayList();
test.TestData = "test data";
ary.Add(test);
Trace.WriteLine(((TestClass)ary[0]).TestData);
Debug.Assert(ary.Contains(test), "Asserting the collection
contains <test>.");
}
With the *Equals* override commented everything works fine: the trace writes
the "test data" string and the assert is quiet.
Could somebody please tell me why if only the *Equals* override is
uncommented the trace still works fine but the assert fails ?
Note: commenting/uncommenting the GetHashCode() doesn't seem to make any
difference.
Thanks in advance...