0

I am reading a string and matching this string to one of the enum values that I have in the following line:

(DataType)Enum.Parse(typeof(DataType), row[0], true);

Is there an alternative way or more effient way to match a string with enum ? I heard that this can be done using reflection, is that possible ? any hint ? would it be more effient ?

2
  • do you want to know that enum value exists with same string name?? Commented May 28, 2012 at 13:11
  • I am adding this string as an enum to a list<enum> Commented May 28, 2012 at 13:13

1 Answer 1

2

No, you're definately doing this right IMO. What you might be confusing it with is that often people mark-up enums with a DescriptionAttribute to go the other way - converting an enum to a string for display purposes:

public enum SomeEnum
{
  [Description("This is value One")]
  Value1,
  [Description("This is value Two")]
  Value2
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.