今天使用Visual Studio 2012時,需用到switch statement來判斷enum的資料

剛好enum的值又多,人又很懶也隱約記得VS有提供auto fill的功能

上網查一下順便記起來以免又忘了如何操作

 

1. 假設有enum定義如下

 public enum Stage { 請假人蓋章=0, 職務代理人蓋章=1, 系所主管組長蓋章=2, 單位主管蓋章=3, 有關處室會章=4, 校長核示=5 }

 

2.變數值

Stage stage=GetStage();

 

3. 鍵入switch後並按兩下Tab, switch_on會被反白

switch (switch_on)
{
default:
}

 

4. 接著輸入stage變數取代switch_on然後按一下Tab及向下方向鍵

 

switch (stage)
{
case Stage.請假人蓋章:
break;
case Stage.職務代理人蓋章:
break;
case Stage.系所主管組長蓋章:
break;
case Stage.單位主管蓋章:
break;
case Stage.有關處室會章:
break;
case Stage.校長核示:
break;
default:
break;
}

and Voila! 少打一些字也節省不少時間

 

arrow
arrow
    文章標籤
    Visual Studio
    全站熱搜

    啄雲 發表在 痞客邦 留言(1) 人氣()