我可以创建枚举值的列表<T>吗?
Can I create a List<T> of enumerated values?
我正在编写 WinForms 应用程序,我想创建一个可枚举类型。如果我写
enum Op { plus, minus, mul, div };
我无法创建 List<Op> ops;
— 它会导致错误
"Op" is not a valid generic argument
(System::Collections::Generic::List
是 std::vector
的类比)
我解决了这个声明
public enum class Op { plus, minus, mul, div };
外面class MyForm
那我就可以把它当作
List<Op> ops;
ops.Add(Op::plus);
如果有更好的解决办法请留言
我正在编写 WinForms 应用程序,我想创建一个可枚举类型。如果我写
enum Op { plus, minus, mul, div };
我无法创建 List<Op> ops;
— 它会导致错误
"Op" is not a valid generic argument
(System::Collections::Generic::List
是 std::vector
的类比)
我解决了这个声明
public enum class Op { plus, minus, mul, div };
外面class MyForm
那我就可以把它当作
List<Op> ops;
ops.Add(Op::plus);
如果有更好的解决办法请留言