I wanted to do something simple like checking my own Color variable
against Color.Black, and == returned false, even though their RGB
values were all 0! Of course, there's the A (alpha) value, but that's
0, too (I assume). I guess I naively thought that == would be
overloaded to work in this case, just dealing with RGB. I guess I
have to compare R, G, and B separately.
Is this the standard way to deal with this? I know some structs just
can't be compared, but this is a color. I could even see that the
alpha channel needs to be the same, but I would think it is always 0,
unless otherwise needed.
Zytan 2 5487
Zytan <zy**********@gmail.comwrote:
I wanted to do something simple like checking my own Color variable
against Color.Black, and == returned false, even though their RGB
values were all 0! Of course, there's the A (alpha) value, but that's
0, too (I assume). I guess I naively thought that == would be
overloaded to work in this case, just dealing with RGB. I guess I
have to compare R, G, and B separately.
Is this the standard way to deal with this? I know some structs just
can't be compared, but this is a color. I could even see that the
alpha channel needs to be the same, but I would think it is always 0,
unless otherwise needed.
From the docs:
<quote>
This structure only does comparisons with other Color structures. To
compare colors based solely on their ARGB values, you should use the
ToArgb method. This is because the Equals and op_Equality members
determine equivalency using more than just the ARGB value of the
colors. For example, Black and FromArgb(0,0,0) are not considered
equal, since Black is a named color and FromArgb(0,0,0) is not.
</quote>
Not exactly friendly, but at least it explains it!
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
From the docs:
>
<quote>
This structure only does comparisons with other Color structures. To
compare colors based solely on their ARGB values, you should use the
ToArgb method. This is because the Equals and op_Equality members
determine equivalency using more than just the ARGB value of the
colors. For example, Black and FromArgb(0,0,0) are not considered
equal, since Black is a named color and FromArgb(0,0,0) is not.
</quote>
Not exactly friendly, but at least it explains it!
Ah, yes, not friendly, at all, but yes, it does explain it, which is
nice. I had a feeling what it said was the case. Well, the evidenece
suggests it, but now I know why -- one is a named color, and the other
isn't. I was trying to find the default zero'ed value for Color, and
I assumed it would be Black or FromArgb(0,0,0).
Thanks, Jon!
Zytan This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bob Gregory |
last post by:
Hi all, I'm utter C# newbie, do be gentle.
VS2005 Express refuses point blank to install on my box, so I'm stuck
with C# 1.0 unless someone can point me to a C#2.0 compiler elsewhere.
I have...
|
by: Adam Dockter |
last post by:
I have a couple questions about comparing images. I notice the imagelist
collection of images doesn't provide any comparison of images, and the
System.Drawing.Image.Equal function will not compare...
|
by: Peter Rilling |
last post by:
Hi.
Two of my biggest complaints about structure in c# is that 1) You cannot
implement a default constructor and 2) You cannot initialize fields on the
declaration line.
I would like to...
|
by: ma740988 |
last post by:
There's a need for me to move around at specified offsets within
memory. As as a result - long story short - unsigned char* is the type
of choice.
At issue: Consider the case ( test code ) where...
|
by: barcaroller |
last post by:
Is it legal to compare the contents of two multi-field variables (of the
same struct) using "==" and "!="?
struct
{
int a;
int b;
} x,y;
...
| |
by: John |
last post by:
I'm having a major problem trying to use value types like
System::Drawing::Rectangle with std::vector. Is it possible to use STL
containers with these type of objects, or am I just doing something...
|
by: forest demon |
last post by:
for example, let's say I do something like,
System.Diagnostics.Process.Start("notepad.exe","sample.txt");
if the user does a SaveAs (in notepad), how can i capture the path that
the user...
|
by: Dom |
last post by:
I'm really confused by the difference between a Struct and a Class?
Sometimes, I want just a group of fields to go together. A Class
without methods seems wrong, in that it carries too much...
|
by: jonpb |
last post by:
Using .NET 3.5, I need to pass an array of structs as parameter to a C++
unmanaged function.
The C++ dll stores some data in an unmanaged cache, the function writes
the values into the array of...
|
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,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |