Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

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.Black):
                    return Convert.ToInt32(Skins.Black);
            }
       

But this part:
Convert.ToString(Skins.Black):

Gives an error: A constant value is expected.

How can I reproduce this functionality in C#? thanks.
ASKER CERTIFIED SOLUTION
Avatar of p_davis
p_davis

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Starr Duskk

ASKER

gives error:
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.
 
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial