Search code examples
c#.netsystem.drawing

Compare ColorBlends


How can I check if two ColorBlends have different Colors values?

I tried the following code

ColorBlend Blend1 = new ColorBlend();
Blend1.Colors = new Color[] { Color.White, Color.Black };
Blend1.Positions = new float[] { 0.0f, 1.0f };

ColorBlend Blend2 = new ColorBlend();
Blend2.Colors = new Color[] { Color.White, Color.Black };
Blend2.Positions = new float[] { 0.0f, 1.0f };

if (Blend1.Colors != Blend2.Colors)
{
    MessageBox.Show("Values are Different");
}

It doesn't work because when the Colors values are the same for both Blends, it still says they're not equal!


Solution

  • The check is not correct. You can't compare two arrays in that way. You have to go through and compare each item to make sure they are equal