![](/img/trans.png)
[英](C#) How can I convert my Enum to a dictionary getting the VALUE as the attribute and the KEY as the char(value of the enum)?
[英]C# - how do I find a key value inside an enum with a property?
鉴于C#enum:
public enum options: byte
{
yes = 0,
no = 22,
maybe = 62,
foscho = 42
}
如果给出字节62,你如何检索字符串'maybe'?
您可以通过ToString()
将其强制转换为enum和retreive:
var result = ((options)62).ToString();
var stringValue = Enum.GetName(typeof(options), 62); // returns "maybe"
您可能还想在支票中包装:
if (Enum.IsDefined(typeof(options), 62))
{
var stringValue = Enum.GetName(typeof(options), 62); // returns "maybe"`
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.