473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Testing equality of Pen objects

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.
Nov 15 '05 #1
2 1320
Does the Pen object have a "ToString" perhaps comparing the string would be
enough?

"Tristan" <tr************@yahoo.co.uk> wrote in message
news:7f**************************@posting.google.c om...
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.

Nov 15 '05 #2

I think, it doesn't work, the "ToString" will return the type, something like this "System.Drawing.Pen". I think he must try to put, for example, a name to the pen, and then compare by name, or somethin like that..

I hope this help...
Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Marius Bernklev | last post by:
In python, it seems like immutable objects are equal under both equality and identity: >>> 5 == 5 True >>> 5 is 5 True >>> "hei" == "hei" True >>> "hei" is "hei"
2
by: Tristan | last post by:
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")
40
by: Ike Naar | last post by:
In K&R "The C++ programming language (2nd ANSI C edition), the reference manual states (paragraphs 7.9 and 7.10) that pointer comparison is undefined for pointers that do not point to the same...
4
by: Matt Burland | last post by:
I'm a little confused about the way the default equality operator works with classes. Here's the situation, I have two comboboxes that are each filled with different object (i.e. ComboBox1 contains...
37
by: spam.noam | last post by:
Hello, Guido has decided, in python-dev, that in Py3K the id-based order comparisons will be dropped. This means that, for example, "{} < " will raise a TypeError instead of the current...
7
by: Gary Brown | last post by:
Hi, In C#, how do you determine two objects are the "same" rather than "equal?" In C/C++ you can check the addresses and LISP provides a rich set of equality operators but C# appears ambiguous....
3
by: toton | last post by:
Hi, I have a struct Point { int x, int y; } The points are stored in a std::vector<Pointpoints; (global vector) I want to add equality (operator == ) for the point, which will check equality...
16
by: DamienS | last post by:
In the interests of me saving hair, can someone please explain to me what's going on below? Why doesn't == work in comparing two int's when cast as objects? They're the same type. Note that it...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.