Zytan <zytanlithium@gmail.comwrote:
Quote:
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 - <skeet@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