if (bool) { } else { }

switch (v) { case v1: ... break; case v2: ... break; ... default: ... break; }

do { } while (bool);

while (bool) { }

for (int i; i < 10; i++) { }

foreach (Type item in items) { }

break;

continue;

goto;


C# 的 switch 语句支持字符串, 但好像只能用 const string 类型的变量.
using System;

class MyClass
{
    static void Main()
    {
        string[] str = { "a", "bb", "ccc" };

        const string s1 = "bb";
        const string s2 = "ccc";

        foreach (string s in str)
        {
           switch(s)
           {
               case s1: Console.WriteLine(s.Length); break;
               case s2: Console.WriteLine(s.Length); break;
               default: Console.WriteLine(s); break; 
           }
        }

        Console.ReadKey();
    }
}

posted on 2008-12-30 23:49  万一  阅读(1779)  评论(0编辑  收藏  举报