给定一个构造函数
public MyObject(int id){
ID = id;
}
还有两个枚举:
public enum MyEnum1{
Something = 1,
Anotherthing = 2
}
public enum MyEnum2{
Dodo = 1,
Moustache= 2
}
是否可以将通用枚举作为构造函数的参数传递? 我正在寻找以下解决方案:
public MyObject(enum someEnum){
ID = (int)someEnum;
}
那么你可以这样做:
var newObject = new MyObject(MyEnum1.Something);
var anotherObject = new MyObject(MyEnum2.Dodo);
MyBase b = new MySub<EnumA>(EnumA.SomeValue); int n = b.ID;
- 15ee8f99-57ff-4f92-890c-b56153new MyObject((int)MyEnum1.Something);
- Thomas Ayoubvar newObject = myFactory.Create(ObjectType.One)
。 - radarbob