Sorry I can't help. I always thought that
if (p1.Equals(p2))
would compare to see if the objects were equivilent (ie refered to 2
distinct objects that had identical properties)
and
if (Pen.Equals(p1,p2))
would check to see if both referenced the same object.
So I would have thought that your comparison would work.
However, on investigation, I found the following: at
http://msdn.microsoft.com/library/de...ualstopic1.asp
Remarks
The default implementation of Equals supports reference equality only, but
derived classes can override this method to support value equality.
So like you say, I guess you will have to write a method that compares all
the properties that are important to you in this situation. What a PITA!
ChrisM
"Tristan" <an*******@discussions.microsoft.com> wrote in message
news:49**********************************@microsof t.com...
Hi,
I'm trying to test if two Pen objects are equal as shown below:
Pen p1 = new Pen(Color.Black);
Pen p2 = new Pen(Color.Black);
if (p1.Equals(p2))
{
Console.WriteLine("These pens equal");
}
The problem is that the if statement doesn't return true, I would have
thought that p1 and p2 are the same. Is the only way round this to write my
own function which compares every single property of Pen? That would be very
laborious and time consuming!
Help much appreciated.
Tristan.