C# C语言中枚举到整数数组的一行转换#
在尝试将枚举转换为其值的int[]时,我最初提出了冗长的:C# C语言中枚举到整数数组的一行转换#,c#,linq,enums,C#,Linq,Enums,在尝试将枚举转换为其值的int[]时,我最初提出了冗长的: Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope)) .Cast<Isolations.Enumerations.TypeSelectionScope>().Select(t => (int)t).ToArray() 这将生成一个类型错误,在其中添加一些强制转换将使其与第一次尝试一样混乱 我还尝试了对int[]的直接强制转换,但没有成功:
Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope))
.Cast<Isolations.Enumerations.TypeSelectionScope>().Select(t => (int)t).ToArray()
这将生成一个类型错误,在其中添加一些强制转换将使其与第一次尝试一样混乱
我还尝试了对int[]
的直接强制转换,但没有成功:
Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope)).Cast<int[]>()
Enum.GetValues(typeof(Isolations.Enumerations.TypeSelectionScope)).Cast()
将ToArray()
添加到此阵列上也会失败
那么,哪种单行解决方案不凌乱呢?迭代一个集合,并将每个项强制转换为t
您正试图将每个实例强制转换为int[]
-您希望将它们强制转换为int
:
.Cast<int>()
.Cast()
遍历集合并将每个项强制转换为T
您正试图将每个实例强制转换为int[]
-您希望将它们强制转换为int
:
.Cast<int>()
.Cast()