程序中有名為accountType的AccountTypes?,F在想當accountType時savings的時候執行一種命令,Chequing的時候執行另一種,Investment的時候執行第三種,所以想用switch來完成,但是Case那里不知道寫什么
1 回答

青春有我
TA貢獻1784條經驗 獲得超8個贊
enum AccountTypes { Savings, Chequing, Investment };
AccountTypes oneType;
.....
switch (oneType)
{
case AccountTypes.Savings:
....
break;
case AccountTypes.Chequing:
....
break;
case AccountTypes.Investment:
....
break;
default:
break;
}
添加回答
舉報
0/150
提交
取消