Go to content Go to navigation Go to search
Input != Output · May 21, 04:14 PM

This is the sort of thing that drives programmers mad…

Consider the following C# code:

  Color inputColor = Color.White;
  Bitmap bitmap = new Bitmap(1, 1);
  bitmap.SetPixel(0, 0, inputColor);
  Color outputColor = bitmap.GetPixel(0, 0);
  if (inputColor == outputColor)
    Console.WriteLine("Same color");
  else
    Console.WriteLine("Different color");
  if (inputColor.Equals(outputColor))
    Console.WriteLine("Same color");
  else
    Console.WriteLine("Different color");

You would expect the output to be:

Same color
Same color

and of course you would be wrong.

Why?

Because inputColor is a named color (White, RGBA) and outputColor is an unnamed color (RGBA).

Obvious huh?

commenting closed for this article

Wii Kicks Financial Ass! So much for MacOS X on the iPhone being virus free...