我在operation.cs中声明了一个枚举类型:
public enum order
{
NewAccount,
FindAccount
}
在test.cs中使用的时候报错:
public class test
{
public static void Main(String[] args)
{
order operationOrder;
Console.WriteLine(operationOrder.NewAccount);
}
}
无法使用实例引用访问静态成员“order.NewAccount”;改用类型名来限定它
order operationOrder;
string value = Console.ReadLine();
operationOrder = (order)Enum.Parse(typeof(order), value);
保证value是NewAccount和FindAccount之一
order operationOrder=order.NewAccount
Console.WriteLine(order.NewAccount);
Code
//Invoke Order Enum
public void InvokeOrderEnum(){
if (true) {
ExecuteMethod(order.NewAccount);
}else{
ExecuteMethod(order.FindAccount);
}
}
// Execute Method
public void ExecuteMethod(Order operationOrder) {
switch (operationOrder)
{
case order.NewAccount:
//TODO
break;
case order.FindAccount:
//TODO
break;
}
}
看你序列化保存或输入的时候如何选择: int 或 string.
前者://对机器友好
Order order = (Order)(int.parse(Console.ReadLine());//强制转换
后者://对人友好
Order order;
string temp = Console.ReadLine();
swicth(temp){
case(Order.New.ToString()):
order = Order.New;
break;
case(Order.Final.ToString()):
order = Order.Final;
break;
default:
throw New Exception(string.Concat("Unkown Order: ", temp));
break;
}