enum Q

  • Thread starter Thread starter JezB
  • Start date Start date
J

JezB

Given an enum :

public enum FlavourCategory {None = -1, Personal = -3, Local = -2,
Predefined = 1};

How can I convert a string eg. "-2" into a FlavourCategory ? I dont want to
write a switch statement.
 
JezB said:
Given an enum :

public enum FlavourCategory {None = -1, Personal = -3, Local = -2,
Predefined = 1};

How can I convert a string eg. "-2" into a FlavourCategory ? I dont want to
write a switch statement.

Just convert it to an int and then cast it:

int foo = int.Parse("-2");
FlavourCategory bar = (FlavourCategory) foo;
 
Hi,

string categoryName = ((FlavourCategory)(-2)).ToString();

categoryName, in this case, will have the value "Local".

HTH,
APG
 
FlavourCategory var =
(FlavourCategory)Enum.Parse(typeof(FlavourCategory),"-2");
 

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

Similar Threads

Enum TypeConverter 3
about enum 3
Enum Extentions 7
Merge Info From Two Enums 1
Spaces in Enum 11
Question about enum values 10
Enums Type Question 4
I have small probalem 4

Back
Top