Color.Equals seems totally useless

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ben Voigt [C++ MVP]

    Color.Equals seems totally useless

    I guess this must be a well-known issue that I just hit my head on.

    Color.Equals doesn't apply the usual equality test.

    For example:

    using (g = Graphics.FromIm age(bmp))
    g.FillRectangle (Brushes.Black, new Rectangle(Point .Empty, bmp.Size));

    One might expect that for any (x, y) inside the image bounds,

    bmp.GetPixel(x, y) == Color.Black

    But it's not.

    GetPixel returns an unnamed black color, while Color.Black returns a named
    black color, and while the value is the same (0xff000000) they compare
    unequal!

    Anyone know a valid reason for this insanity before I post a bug on Connect?


  • Steve Gerrard

    #2
    Re: Color.Equals seems totally useless

    Jon Skeet [C# MVP] wrote:
    >
    Another concrete example:
    >
    string x = "mail";
    string y = "MAIL";
    bool b = (x.ToUpper() == y);
    >
    What's the value of b? I suspect if you ask 1000 C# developers, almost
    all of them would say "true". Very few of them would say "It depends
    whether or not the current culture is Turkish" which is the correct
    answer.
    >
    As one of the 1000, may I ask what x.ToUpper() is when the current culture is
    Turkish? :)


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Color.Equals seems totally useless

      On Feb 19, 9:23 am, "Steve Gerrard" <mynameh...@com cast.netwrote:
      Another concrete example:
      >
      string x = "mail";
      string y = "MAIL";
      bool b = (x.ToUpper() == y);
      >
      What's the value of b? I suspect if you ask 1000 C# developers, almost
      all of them would say "true". Very few of them would say "It depends
      whether or not the current culture is Turkish" which is the correct
      answer.
      >
      As one of the 1000, may I ask what x.ToUpper() is when the current culture is
      Turkish? :)
      The I has an accent on it. Lower-casing has the same effect (so
      y.ToLower()==x wouldn't help). I first ran into this in Java, with
      exactly "mail" - I was trying to compare headers.

      It's a particularly nasty bit of i18n.

      Jon

      Comment

      Working...