I have created an Enum and want to read the text value from it. The Enum is as below:
public enum MethodID
{
/// <summary>
/// The type of request being done. Inquiry.
/// </summary>
[EnumTextValue("01")]
Inquiry,
/// <summary>
/// The type of request being done. Update
/// </summary>
[EnumTextValue("02")]
Update,
}
Now I want to assign the value of enum to a request object methodID. I tried the following code, but it didnt worked:
request.ID = Enum.GetName(typeof(MethodID), MethodID.Inquiry);
What I want is to assign the value “01” to the data member of request data contract (request.ID) that I will fetch from the Enum MethodID. How will I get this? Please help
If you want just to get int value then you can declare enum as
And then use casting to int:
If you want to get string value from attribute then this is the static helper method