0

so i am trying to change the background color based on the current color by using a switch however iam getting an error.

switch (BtnColor.BackgroundColor)
            {
                case Color.Red:
                    BtnColor.BackgroundColor = Color.White;
                    break;
                case Color.White:
                    BtnColor.BackgroundColor = Color.Blue;
                    break;
                default:
                    BtnColor.BackgroundColor = Color.Red;
                    break;
            }

i am getting the following error on: case Color.White: and case Color.Red:

A constant value is expected

Paul
  • 67
  • 6

1 Answers1

1

Colors are not constants, and that's what you're supposed to use when using Switch statements.

Predefined Colors are Static Properties of the Color class, so that can't be used.

Sample Color Definition

In this case you can use if/then/else statements to achieve the same exact thing.

Also refer to this answer

Rick
  • 345
  • 2
  • 13