惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
Engineering at Meta
Engineering at Meta
美团技术团队
H
Hackread – Cybersecurity News, Data Breaches, AI and More
博客园 - 司徒正美
I
InfoQ
S
SegmentFault 最新的问题
博客园 - 叶小钗
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
IT之家
IT之家
博客园 - Franky
大猫的无限游戏
大猫的无限游戏
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
月光博客
月光博客
The Cloudflare Blog
U
Unit 42
GbyAI
GbyAI
L
LangChain Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - Forrest Gump

关于LINQ中数据库连接字符串的问题 项目开发经验-ASP.NET项目开发中的异常处理 关于模态窗口(showModalDialog)的专题【收藏】 C#面试题 C# 将数据导出到Excel汇总 关于Assembly.CreateInstance()与Activator.CreateInstance()方法 PowerDesigner概念设计模型(CDM)中的3种实体关系 C#基础概念二十五问 Microsoft .NET Pet Shop 4:将 ASP.NET 1.1 应用程序迁移到 2.0 用Inno Setup制作WEB程序安装包 冒泡法数组排序与 System.Array.Sort()排序性能比较 堆排序 (Heap sort) 合并排序法(Merge Sort) 希尔排序法 quick sort C#中一些很基础但有经常导致错误的一些概念 Enterprise Library Step By Step系列(十六):使用AppSetting Application Block Enterprise Library Step By Step系列(十五):配置应用程序块——设计篇 创建基于消息队列(MSMQ)的异步日志
关于switch的小技巧
Forrest Gump · 2008-01-21 · via 博客园 - Forrest Gump


switch中的case穿越

 1using System;
 2
 3class SwitchSample
 4{
 5    public static void Main()
 6    {
 7        Console.WriteLine("Please enter the letter:");
 8        string letter = Console.ReadLine();
 9
10        switch(letter)
11        {
12            case "a":
13            case "A":
14            case "b":
15            case "B":
16                Console.WriteLine("it's Ok");
17                break;
18            case "c":
19            case "C":
20            default:
21                Console.WriteLine("default!!!!!");
22                break;
23        }

24    }

25}

输入a
运行结果
it's ok

当case中放空语句的时候,流程控制会直接穿越这个case到下一个case,直到非空语句为止,所以上面的程序当我们输入a的时候,会直接穿越到16行执行。我们可以利用这个特点让多个条件执行同一个语句。

posted @ 2008-01-21 18:06  Forrest Gump  阅读(419)  评论(0)    收藏  举报

刷新页面返回顶部