VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • c#语法练习5 语句

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 

 

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();
  }
}

 



相关教程