• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • C# 語言規范--1.6 語句

    發表于:2007-07-14來源:作者:點擊數: 標簽:
    C# 語言規范--1.6 語句: C# 中的大多數語句都是直接從 C 和 C++ 借用的,但有一些值得注意的添加和修改。下表列出了可用的語句類型,并提供了每種類型的示例。 語句 示例 語句列表和塊語句 static void Main() { F(); G(); { H(); I(); } } 標記語句和 goto
    C# 語言規范--1.6 語句:

    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");    }}
    checkedunchecked 語句
    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 語句
    static void Main() {    using (Resource r = new Resource()) {        r.F();    }}


    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>