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

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - 極速麻醉

论程序设计方法(轉貼) 感冒食疗中药方 ASP.NET HTTP 运行时 软件开发项目计划编制过程(下) 软件开发项目计划编制过程(上) 如何更好地与开发工程师沟通-给测试工程师的建议 软件开发项目计划编制过程(下) 代码设计的探索 (上) 静态方法和类方法有什么区别! 人生目的何在? .NET 技术FAQ (轉載) 創建和使用簡單委托! FreeTextBox在点击上传图片的时候弹出无法找到脚步库"/aspnet_client/system_web/1_1_4322/webuivalidation.js 常数 表達式 今天特別高興!又玩起了星際! 继承和派生 兩個object為什么不相等??
C# 语句大全!
極速麻醉 · 2005-05-10 · via 博客园 - 極速麻醉

C# 中的大多数语句都是直接从 C C++ 借用的但有一些值得注意的添加和修改。下表列出了可用的语句类型,并提供了每种类型的示例。

语句

示例

语句列表和块语句

static void Main() {
    F();
    G();
    {
        H();
        I();
    }
}

标记语句和 goto 语句

static void Main(string[] args) {
    if (args.Length == 0)
        goto done;
    Console.WriteLine(args.Length);

done:
    Console.WriteLine("Done");
}

局部常数声明

static void Main() {
    const float pi = 3.14f;
    const int r = 123;
    Console.WriteLine(pi * r * r);
}

局部变量声明

static void Main() {
    int a;
    int b = 2, c = 3;
    a = 1;
    Console.WriteLine(a + b + c);
}

表达式语句

static int F(int a, int b) {
    return a + b;
}

static void Main() {
    F(1, 2);  // Expression statement
}

if 语句

static void Main(string[] args) {
    if (args.Length == 0)
        Console.WriteLine("No args");
    else
        Console.WriteLine("Args");
}

switch 语句

static void Main(string[] args) {
    switch (args.Length) {
        case 0:
            Console.WriteLine("No args");
            break;
        case 1:
            Console.WriteLine("One arg ");
            break;
        default:
            int n = args.Length;
            Console.WriteLine("{0} args", n);
            break;
    }
}

while 语句

static void Main(string[] args) {
    int i = 0;
    while (i < args.Length) {
        Console.WriteLine(args[i]);
        i++;
    }
}

do 语句

static void Main() {
    string s;
    do { s = Console.ReadLine(); }
    while (s != "Exit");
}

for 语句

static void Main(string[] args) {
    for (int i = 0; i < args.Length; i++)
        Console.WriteLine(args[i]);
}

foreach 语句

static void Main(string[] args) {
    foreach (string s in args)
        Console.WriteLine(s);
}

break 语句

static void Main(string[] args) {
    int i = 0;
    while (true) {
        if (i == args.Length)
            break;
        Console.WriteLine(args[i++]);
    }
}

continue 语句

static void Main(string[] args) {
    int i = 0;
    while (true) {
       Console.WriteLine(args[i++]);
       if (i < args.Length)
            continue;
       break;
    }
}

return 语句

static int F(int a, int b) {
    return a + b;
}

static void Main() {
    Console.WriteLine(F(1, 2));
    return;
}

throw 语句和 try 语句

static int F(int a, int b) {
    if (b == 0)
        throw new Exception("Divide by zero");
    return a / b;
}

static void Main() {
    try {
        Console.WriteLine(F(5, 0));
    }
    catch(Exception e) {
        Console.WriteLine("Error");
    }
}

checked unchecked 语句

static void Main() {
    int x = Int32.MaxValue;

    Console.WriteLine(x + 1);      // Overflow

    checked {
        Console.WriteLine(x + 1);  // Exception
    }    

    unchecked {
        Console.WriteLine(x + 1);  // Overflow
    }
}

lock 语句

static void Main() {
    A a = ...;
    lock(a) {
        a.P = a.P + 1;
    }
}

using statements

static void Main() {
    using (Resource r = new Resource()) {
        r.F();
    }
}