在尝试将枚举转换为其值的 int[] 时,我最初提出了冗长的想法:
Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope))
.Cast<Isolations.Enumerations.TypeSelectionScope>().Select(t => (int)t).ToArray()
它有效,但是..好吧,它并不漂亮。
我进行了一些搜索,发现有人为此目的在多行中使用 ConvertAll()。所以我尝试了内联。
Array.ConvertAll(Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope)), value => (int)value)
这会产生一个类型错误,并且在其中添加一些转换会使它像第一次尝试一样困惑。
我还尝试了直接转换为 int[] 但无济于事:
Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope)).Cast<int[]>()
向其添加 ToArray() 也会失败。
那么,什么是不困惑的单行解决方案?
请您参考如下方法:
