Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6808933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:01:02+00:00 2026-05-26T20:01:02+00:00

Why does this evaluate to false ? Color.FromArgb(255, 255, 255, 255) == Color.White Update

  • 0

Why does this evaluate to false?

Color.FromArgb(255, 255, 255, 255) == Color.White

Update It’s by design.

Here’s a copy from the decompiled Equals function in the Color structure:

public override bool Equals(object obj)
{
    //probably failure to convert from C++ source,
    //the following line should be invalid in C#, nevermind
    if (obj is Color)
    {
        Color color = (Color) obj;
        if (((this.value == color.value) &&
            (this.state == color.state)) &&
             (this.knownColor == color.knownColor))
        {
            return ((this.name == color.name) || 
                   (((this.name != null) && (color.name != null)) && 
                   this.name.Equals(this.name)));
        }
    }
    return false;
}

My question is why on earth would MSFT have me comparing to white the ugly way?!?!?

static bool AreEqual(Color a, Color b)
{
  if (!a.Equals(b))
  {
    return
      a.A == b.A &&
      a.R == b.R &&
      a.G == b.G &&
      a.B == b.B;    
  }
  return true;
}

Also, another thing I don’t get why the 1-arg overload of the FromArgb function in Color takes an int, it should be able to take a uint (0xffffffff)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T20:01:03+00:00Added an answer on May 26, 2026 at 8:01 pm

    This is just how colors in .NET work:

    This structure only does comparisons with other Color structures. To
    compare colors based solely on their ARGB values, you should do the
    following:

    if ( color1.ToArgb() == color2.ToArgb()) …

    This is because the .Equals and == operators determine equivalency
    using more than just the ARGB value of the colors
    . For example,
    Color.Black and Color.FromArgb(0,0,0) are not considered equal since
    Color.Black is a named color and Color.FromArgb(0,0,0) is not.

    Edit: additional answers.

    My question is why on earth would MSFT have me comparing to white the ugly way?!?!?

    If you’re comparing colors in such a way that you want to know whether they’re exactly the same color down to the values of the ARGB components, then you should be comparing them in the “ugly” way. If you’re comparing the colors in the same way that most .NET programmers use the Color structure, then you only want to know if some color is White or Red or Chartreuse, and the “pretty” way (using Equals and ==) is simple, easy to use, and very readable.

    Also, the “ugly” way isn’t the method you posted, it’s this:

    if (color1.ToArgb() == color2.ToArgb()) ...
    

    which isn’t really that ugly.

    Also, another thing I don’t get why the 1-arg constructor of Color takes an int, it should be able to take a uint (0xffffffff)

    I would say it should not be able to take a uint, thanks to the inevitable confusion and color errors that would cause. It’s easy to write a method to do this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does this code always evaluate to false? Both variables are two's complement signed ints.
Does this mean I can't update another table from a trigger if I'm using
Given searchString = 23423asdfa-'' This regular expression should evaluate to false but it does
What does this function do? And how do you evaluate it? How to trace
Does this look like it should work? I'm wanting to generate directions from one
Possible Duplicate: Why does (“foo” === new String(“foo”)) evaluate to false in JavaScript? Over
Why does =FALSE<10000000000 evaluate as FALSE and =FALSE>10000000000 evaluate as TRUE ? I have
* Simple question : Why does this function throw an exception when evaluated ?
Does this function has the same behavior that memset ? inline void SetZeroArray( void
Does this work well as a Singleton in actionscript? i.e. are there any gotchas

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.