原来学枚举的时候,老觉得没有必要这样写。觉得产品类型也无非就是预定的那几种而已。结果在产品的不断开发中,新产品越来越多。产品的类型就变得变来越庞大。每次去查资料来想每种产品类型的编码,费时费利。笨笨这时才想通了,是不是枚举出力的时候了。呵呵~~
1 /// <summary>
2 /// 玩具类型
3 /// </summary>
4 public enum ToyType
5 {
6 /// <summary>
7 /// kitty猫
8 /// </summary>
9 Kitty=0,//此处加上
10 /// <summary>
11 /// 咖啡猫
12 /// </summary>
13 Coffer=1,
14 /// <summary>
15 /// 米其
16 /// </summary>
17 Mickey=2,
18 /// <summary>
19 /// 粉猪猪
20 /// </summary>
21 PinkPig=3
22
23 }
24 static string WriteToyName(ToyType toyType)
25 {
26 string ToyCN="";
27 switch (toyType)
28 {
29 case ToyType.Kitty: ToyCN = "kitty猫";
30 break;
31 case ToyType.Coffer: ToyCN = "咖啡猫";
32 break;
33 case ToyType.Mickey: ToyCN = "米其";
34 break;
35 case ToyType.PinkPig: ToyCN = "粉猪猪";
36 break;
37 }
38 return ToyCN;
39
40 }
2 /// 玩具类型
3 /// </summary>
4 public enum ToyType
5 {
6 /// <summary>
7 /// kitty猫
8 /// </summary>
9 Kitty=0,//此处加上
10 /// <summary>
11 /// 咖啡猫
12 /// </summary>
13 Coffer=1,
14 /// <summary>
15 /// 米其
16 /// </summary>
17 Mickey=2,
18 /// <summary>
19 /// 粉猪猪
20 /// </summary>
21 PinkPig=3
22
23 }
24 static string WriteToyName(ToyType toyType)
25 {
26 string ToyCN="";
27 switch (toyType)
28 {
29 case ToyType.Kitty: ToyCN = "kitty猫";
30 break;
31 case ToyType.Coffer: ToyCN = "咖啡猫";
32 break;
33 case ToyType.Mickey: ToyCN = "米其";
34 break;
35 case ToyType.PinkPig: ToyCN = "粉猪猪";
36 break;
37 }
38 return ToyCN;
39
40 }
这样在对哪种产品进行操作的话。就不会出错了。