Parse string to enum type

后端 未结 8 1195
灰色年华
灰色年华 2020-11-29 09:04

I have an enum type like this as an example:

public Enum MyEnum {
    enum1, enum2, enum3 };

I\'ll read a string from config file. What I n

8条回答
  •  無奈伤痛
    2020-11-29 10:02

    This is an old question, but now .NET 4.5 has Enum.TryParse().

    http://msdn.microsoft.com/en-us/library/dd991317.aspx

提交回复
热议问题