Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のようなDescription属性を持つ列挙型があります:
public enum MyEnum { Name1 = 1, [Description("Here is another")] HereIsAnother = 2, [Description("Last one")] LastOne = 3 }
私は「最後の1つ」の値が3です
それを返すコードは何ですか?
あなたはこのようにすることができます
int lastOneValue = (int) MyEnum.LastOne;
このコードは、「LastOne」ではなく値 2 を返します。
string lastOneString = MyEnum.LastOne.ToString();
このコードは、文字列値として「LastOne」を返します
MyEnum mynum = MyEnum.LastOne;
このコードは、の新しいオブジェクトを作成MyEnumし、その値を「LastOne」に設定します
MyEnum