Starr Duskk
asked on
Switch case constant value is expected
I'm convert a VB select/case statement to C#.
I am passing in the skiname and comparing it to the enumerator string name, and returning the enumerator integer value. I have this:
public int GetSkinIdByName(string skinName)
{
switch (skinName)
{
case Convert.ToString(Skins.Bla ck):
return Convert.ToInt32(Skins.Blac k);
}
But this part:
Convert.ToString(Skins.Bla ck):
Gives an error: A constant value is expected.
How can I reproduce this functionality in C#? thanks.
I am passing in the skiname and comparing it to the enumerator string name, and returning the enumerator integer value. I have this:
public int GetSkinIdByName(string skinName)
{
switch (skinName)
{
case Convert.ToString(Skins.Bla
return Convert.ToInt32(Skins.Blac
}
But this part:
Convert.ToString(Skins.Bla
Gives an error: A constant value is expected.
How can I reproduce this functionality in C#? thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
can't convert type Enums.Skins to string.
How does one retrieve the string value or name (not the #) of an enumerator in C#?
like, how do I get the phrase "Black" or "Default" as opposed to "10" or "14" for comparison. The user is passing in the name "Black" and I want to compare it in the switch statement and return the numeric value "10"
namespace Enums
{
public enum Skins
{
Black = 10,
Default = 14
}
thanks.