![](/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.