下列赋值语句正确的是 Visual C#编程入门之语句

Visual C#编程入门之语句
程序的活动是通过语句(statement)来表达的 C#支持几种不同的语句 许多语句是以嵌入语句的形式定义的 块(block)允许在只能使用单个语句的上下文中编写多个语句 块由一个括在大括号 {} 内的语句列表组成 声明语句(declaration statement)用于声明局部变量和常量 表达式语句(expression statement)用于运算表达式 表达式可以作为语句使用译注 包括方法调用 使用new运算符进行对象分配 使用 = 和复合赋值运算符进行赋值 以及使用 ++ 和 运算符进行增量和减量的运算 选择语句(selection statement)用于根据某个表达式的值 选择执行若干可能语句中的某一个 这一组语句有if和switch语句 迭代语句(iteration statement)用于重复执行嵌入语句 这一组语句有while do for和foreach语句 跳转语句(jump statement)用于传递程序控制 这一组语句有break continue goto throw和return语句 try catch语句用于捕捉在块的执行期间发生的异常 并且 try finally语句用于指定一个终止代码块 不管异常出现与否 它总是被执行 checked和unchecked语句用于控制整型算术运算和转换的溢出检查上 下文 lock语句用于获取给定对象的互斥锁 执行语句 然后释放该锁 using语句用于获取一个资源 执行一个语句 然后处理该资源 表 列出了C#的语句 并逐个提供了示例 表 C#的语句 语 句 示 例 局部变量声明 static void Main(){ int a; int b= c= ; a= ; Console WriteLine(a+b+c); } 局部常量声明 static void Main(){ const float pi= f; const int r= ; Console WriteLine(pi * r * r); } 表达式语句 static void Main(){ int i; i= ; //表达式语句 Console WriteLine(i); //表达式语句 i++; //表达式语句 Console WriteLine(i); //表达式语句 } if语句 static void Main(string[] args){ if(args Length == ){ Console WriteLine( No arguments ); } else{ Console WriteLine( One or more arguments ); } } (续表)语 句 示 例 switch语句 static void Main(string[] args){ int n = args Length; switch(n){ case : Console WriteLine( No arguments ); break; case : Console WriteLine( One argument ); break; default: Console WriteLine( { } arguments n); break; } } while语句 static void Main(string[] args){ int i = ; while(i < args Length){ Console WriteLine(args[i]); i++; } } do语句 static void Main(){ string s; do{ s = Console ReadLine(); if(s!=null) Console WriteLine(s); } while(s != null); } for语句 static void Main(string[] args){ for(int i = ; 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(){ while(true){ string s = Console ReadLine(); if (s == null) break; Console WriteLine(s); } } continue语句 static void Main(string[] args){ for(int i = ; i < args Length; i++){ if (args[i] StartsWith( / )) continue; Console WriteLine(args[i]); } } goto语句 static void Main(string[] args){ int i = ; goto check; loop: Console WriteLine(args[i++]); check: if (i < args Length) goto loop; }
(续表) lishixinzhi/Article/program/net/201311/12296