C# 中如何遍历 Enum 枚举值
Sep 22, 2021
假如我们有如下 Shape 枚举类型, 我们要遍历其中所有的枚举值
1 | public enum Shape |
可以通过 GetValues 方法实现:
1 | var shapes = Enum.GetValues(typeof(Shape)); |
另外我们还可以做一点封装
1 | public static class EnumUtil { |

假如我们有如下 Shape 枚举类型, 我们要遍历其中所有的枚举值
1 | public enum Shape |
可以通过 GetValues 方法实现:
1 | var shapes = Enum.GetValues(typeof(Shape)); |
另外我们还可以做一点封装
1 | public static class EnumUtil { |