defining a const color object

C

Claire

The following code raises an error.
"The expression being assigned to 'CeMate.frmMain.BACKCOLOR' must be
constant"

private const Color BACKCOLOR = Color.AliceBlue;

I want to define some const colors. How do I do this please.
 
J

Jon Skeet [C# MVP]

Claire said:
The following code raises an error.
"The expression being assigned to 'CeMate.frmMain.BACKCOLOR' must be
constant"

private const Color BACKCOLOR = Color.AliceBlue;

I want to define some const colors. How do I do this please.

Just use static readonly instead. Colors can't be const, as only the
following types are valid for constant expressions:

sbyte, byte, short, ushort, int, uint, long, ulong, char, float,
double, decimal, bool, string, any enumeration type, or the null type
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top