我有以下枚举:
public enum LifeCycle
{
Pending = 0,
Approved = 1,
Rejected = 2,
}
我想创造
Dictionary<int, string> LifeCycleDict;
从enum
价值及其toString
有没有办法用linq做到这一点?
(相当于 java 的 enum.values )谢谢。
我有以下枚举:
public enum LifeCycle
{
Pending = 0,
Approved = 1,
Rejected = 2,
}
我想创造
Dictionary<int, string> LifeCycleDict;
从enum
价值及其toString
有没有办法用linq做到这一点?
(相当于 java 的 enum.values )谢谢。
Dictionary<int, string> LifeCycleDict = Enum.GetNames(typeof(LifeCycle))
.ToDictionary(Key => (int)Enum.Parse(typeof(LifeCycle), Key), value => value);
或者
Dictionary<int, string> LifeCycleDict = Enum.GetValues(typeof(LifeCycle)).Cast<int>()
.ToDictionary(Key => Key, value => ((LifeCycle)value).ToString());
或者
Dictionary<int, string> LifeCycleDict = Enum.GetValues(typeof(LifeCycle)).Cast<LifeCycle>()
.ToDictionary(t => (int)t, t => t.ToString());