switch case with enum

G

gane kol

Hi

i am getting "a constant value is required" error when i use the enum value
in case statement/
Any ideas?

sample code:

myconfig.cs
------------
public enum WebHostingTypes
{

[Description("BASIC")] Basic,

[Description("PLUS")] Plus,

[Description("PREM")] Premium

}

product.cs
----------------

switch(WebHostingType)

{

case objCommon.GetEnumValueDescription(myconfig.WebHostingTypes.Basic):
break;

case .....

}

--------------------------------

Even if i tried using a something like

public enum Volume

{

Low,

Medium,

High

}

string myVolume = "Medium";

switch(myVolume)

{

case myconfig.Volume.Medium:
break;

case .....

}

- Gane
 
K

Kevin Spencer

Enumerated values are numbers. If you treat them as such you will have no
problems with them.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
G

gane kol

well, ok. But i couldnt figure why the example below (2nd Example) is not
working for me, but worked for others (found in some tech articles).


Kevin Spencer said:
Enumerated values are numbers. If you treat them as such you will have no
problems with them.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

gane kol said:
Hi

i am getting "a constant value is required" error when i use the enum
value
in case statement/
Any ideas?

sample code:

myconfig.cs
------------
public enum WebHostingTypes
{

[Description("BASIC")] Basic,

[Description("PLUS")] Plus,

[Description("PREM")] Premium

}

product.cs
----------------

switch(WebHostingType)

{

case objCommon.GetEnumValueDescription(myconfig.WebHostingTypes.Basic):
break;

case .....

}





*********************** 2ND EXAMPLE
 
K

Kevin Spencer

well, ok. But i couldnt figure why the example below (2nd Example) is not
working for me, but worked for others (found in some tech articles).

I wouldn't know, as I haven't seen them. However, I can't see any good
reason for doing so. You have to be careful what tech articles you read, and
by whom they are written.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.

gane kol said:
well, ok. But i couldnt figure why the example below (2nd Example) is not
working for me, but worked for others (found in some tech articles).


Kevin Spencer said:
Enumerated values are numbers. If you treat them as such you will have no
problems with them.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
What You Seek Is What You Get.

gane kol said:
Hi

i am getting "a constant value is required" error when i use the enum
value
in case statement/
Any ideas?

sample code:

myconfig.cs
------------
public enum WebHostingTypes
{

[Description("BASIC")] Basic,

[Description("PLUS")] Plus,

[Description("PREM")] Premium

}

product.cs
----------------

switch(WebHostingType)

{

case objCommon.GetEnumValueDescription(myconfig.WebHostingTypes.Basic):
break;

case .....

}





*********************** 2ND EXAMPLE
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top