0

I searched around, everyone else who had this problem was using the .ToString method and I am not so I am at a loss.

On the last line I get a return of "A Constant Value is expected"

I know if I remove the part where I give the enum's values it works, but that kinda defeats the purpose of me using an Enum. Any suggestions about the best way to accomplish this?

        public enum Colors
    {
        Blue = "0000FF",
        Red = "FF0000",
        Green= "00FF00"
    }
        private void colorstuff(Colors Color){
            switch (Color ){
                case Colors.Blue:

            }
        }

**EDIT So I have been made aware that ENUM's cannot have a STRING type. Can anyone suggest a method for making a SET of String Types? If I just declare

        const Blue = "0000FF",
        const Red = "FF0000",
        const Green= "00FF00"

They are not attached to one another.

Cade
  • 97
  • 2
  • 8

2 Answers2

2

Enums are based on int data type, so you need to declare them like this:

Blue = 0x0000FF 

Alternatively declare a class:

    public static class MyColours
    {
        public  const string Blue = "0000FF";
    }
Rikalous
  • 4,514
  • 1
  • 40
  • 52
  • So my Enum section won't even compile? Good deal. – Cade Dec 16 '14 at 16:09
  • Well, `int` by default - but you can specify other integer-based types as the underlying type too. – Jon Skeet Dec 16 '14 at 16:09
  • The above example is just fake code to make my example. I actually need something with a string value. I need an underlying value to be a string and I would like it to work exactly like an ENUM does instead of having detached constants by just declaring const String Blue="0000FF"; How would I create a "SET" of constants that all have string values? – Cade Dec 16 '14 at 16:13
  • What if I create a new public class and made the sub constants public also. Does this look like a good alternative? Does anyone see any potential issues using this method? This just seems like an odd way to accomplish this.' `code public static class Colors { public String Value=""; public const String Blue = "0000FF"; public const String Red = "FF0000"; public const String Green= "00FF00"; }` – Cade Dec 16 '14 at 17:02
0

dear you can't define enum like this , because it's int type.

 public enum Colors
    {
        Blue = 0000FF,
        Red = FF0000,
        Green= 00FF00
    }
Wajihurrehman
  • 567
  • 3
  • 15
  • 29