获取包含枚举值的整数表示的字符串

时间:2023-01-26 14:15:27
string userTypeId = ((int)ERPSystemUserType.Basic).ToString();

public enum ERPSystemUserType
{
    Basic = 20,
    Upgraded = 30
}

if I use ToString(), return the enum type's string value, however I want to use the defined int value.

如果我使用ToString(),返回枚举类型的字符串值,但是我想使用定义的int值。

Is there any attribute or way, I could use for return string by is number of the enum? Instead of doing ((int)ERPSystemUserType.Basic).ToString(). And don't want to use the Extension, then I have to use to every enum.

是否有任何属性或方式,我可以用于返回字符串是枚举的数字?而不是做((int)ERPSystemUserType.Basic).ToString()。并且不想使用Extension,那么我必须使用每个枚举。

1 个解决方案

#1


4  

Use .ToString("D"). See Enumeration Format Strings.

使用.ToString(“D”)。请参阅枚举格式字符串。

#1


4  

Use .ToString("D"). See Enumeration Format Strings.

使用.ToString(“D”)。请参阅枚举格式字符串。