C#语言中switch模块case default
来源:互联网 发布:gns3 路由器端口ip 编辑:程序博客网 时间:2024/05/16 15:30
package flowcontrol;
1.
2. publicclass SwitchCase {
3. // first default
4. publicstaticvoid testFirst(int i) {
5. switch (i) {
6. default:
7. System.out.println("default");// first default
8. case 1:
9. System.out.println("one");
10. case 2:
11. System.out.println("two");
12. case 3:
13. System.out.println("there");
14. }
15. }
16.
17. // last default
18. publicstaticvoid testLast(int i) {
19. switch (i) {
20. case 1:
21. System.out.println("one");
22. case 2:
23. System.out.println("two");
24. case 3:
25. System.out.println("there");
26. default:
27. System.out.println("default");// last default
28. }
29. }
30.
31. // middle default
32. publicstaticvoid testMiddle(int i) {
33. switch (i) {
34. case 1:
35. System.out.println("one");
36. case 2:
37. System.out.println("two");
38. default:
39. System.out.println("default");// middle default
40. case 3:
41. System.out.println("there");
42.
43. }
44. }
45.
46. publicstaticvoid main(String[] args) {
47. // first default
48. testFirst(2);
49. System.out.println("------------------");
50. testFirst(9);
51.
52. System.out.println("|||||||||||||||||||||||||||||||||||");
53.
54. // last default
55. testLast(2);
56. System.out.println("----------------");
57. testLast(9);
58.
59. System.out.println("|||||||||||||||||||||||||||||||||||");
60. // middle default
61. testMiddle(2);
62. System.out.println("----------------");
63. testMiddle(9);
64.
65. }
66.
67. }
2. there
3. ------------------
4. default
5. one
6. two
7. there
8. |||||||||||||||||||||||||||||||||||
9. two
10. there
11. default
12. ----------------
13. default
14. |||||||||||||||||||||||||||||||||||
15. two
16. default
17. there
18. ----------------
19. default
20. there
1.
2. publicclass SwitchCase {
3. // first default
4. publicstaticvoid testFirst(int i) {
5. switch (i) {
6. default:
7. System.out.println("default");// first default
8. case 1:
9. System.out.println("one");
10. case 2:
11. System.out.println("two");
12. case 3:
13. System.out.println("there");
14. }
15. }
16.
17. // last default
18. publicstaticvoid testLast(int i) {
19. switch (i) {
20. case 1:
21. System.out.println("one");
22. case 2:
23. System.out.println("two");
24. case 3:
25. System.out.println("there");
26. default:
27. System.out.println("default");// last default
28. }
29. }
30.
31. // middle default
32. publicstaticvoid testMiddle(int i) {
33. switch (i) {
34. case 1:
35. System.out.println("one");
36. case 2:
37. System.out.println("two");
38. default:
39. System.out.println("default");// middle default
40. case 3:
41. System.out.println("there");
42.
43. }
44. }
45.
46. publicstaticvoid main(String[] args) {
47. // first default
48. testFirst(2);
49. System.out.println("------------------");
50. testFirst(9);
51.
52. System.out.println("|||||||||||||||||||||||||||||||||||");
53.
54. // last default
55. testLast(2);
56. System.out.println("----------------");
57. testLast(9);
58.
59. System.out.println("|||||||||||||||||||||||||||||||||||");
60. // middle default
61. testMiddle(2);
62. System.out.println("----------------");
63. testMiddle(9);
64.
65. }
66.
67. }
输出如下所示:
1. two2. there
3. ------------------
4. default
5. one
6. two
7. there
8. |||||||||||||||||||||||||||||||||||
9. two
10. there
11. default
12. ----------------
13. default
14. |||||||||||||||||||||||||||||||||||
15. two
16. default
17. there
18. ----------------
19. default
20. there
分析如下:
(1)switch语句关键地方是进入点,有了进入点没有break的情况下会执行到底,或遇到break
(2)没有匹配值的时候default就是进入点,进入default以后会和普通进入点一样,如果没有break继续执行下面语句
- C#语言中switch模块case default
- switch与case及default
- switch...case...default...执行顺序
- JavaScript -- switch,case,break,default
- switch中case...用法-c语言
- C#中switch...case用法问题
- C# switch case
- js switch case default 的用法
- switch case break default 判断语句
- javascript switch default写在case前
- 关于switch-case的default坑
- switch case语句中的default语句
- switch(A){case a: break;........default :}用法
- 【Java基础知识】switch表达式、case穿透、default、switch结束条件
- C语言中switch case语句的实现
- haXe语言中改进的switch...case语法
- C语言中switch case语句的实现
- C语言中switch case的类型比较机制
- 《那些年啊,那些事——一个程序员的奋斗史》——19
- 解决Eclipe安装不上androd的ADT的办法
- 《那些年啊,那些事——一个程序员的奋斗史》——10
- C# DataView实现前N行筛选
- 旅程的开始
- C#语言中switch模块case default
- linux下禁用笔记本自带键盘和touchpad
- DataTable、DataRow 手动赋值
- new/malloc的内存不释放
- JavaScript进制转换
- 计算机方面最好的论文
- oracle 11g 学习笔记 10_30(2)_数据字典和动态性能视图
- Verilog 语法总结(二)
- sgu 120 Archipelago