新Visual C# 2008程序设计案例教程 电子教案 源代码 3.pptVIP

  • 3
  • 0
  • 约2.27万字
  • 约 112页
  • 2015-11-19 发布于广东
  • 举报

新Visual C# 2008程序设计案例教程 电子教案 源代码 3.ppt

主讲教师: 本课学时: 联系方式: 第三章 C#编程基础 本章的学习目标 在C#中使用分支结构 掌握各种分支结构的区别 在C#中使用循环语句 掌握循环语句的相同和区别 了解和掌握数组 掌握函数的应用 知道和学会怎样用字符串 3. 1 分支语句 期末过后,班主任要将百分成绩转换为等级制,需要进行等级判断,90~100分为A,80~89为B,70~79为C,60~69为D,60分以下为E。这时必须转移或改变程序的执行的顺序。而用分支语句,能够容易地实现这一功能。 3. 1 分支语句 if语句??? switch语句?? 三元运算符 If语句 if语句 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace @if { class EvenOdd { public static void Main() { int a; a = Int32.Parse(Console.ReadLine()); if (a % 2 == 0) Console.WriteLine(This is even\n); else Console.WriteLine(This is odd\n); Console.ReadKey(); } } } 输出结果: Switch语句 各个 case 标签不必连续,也不必按特定顺序排列 default 标签可位于 switch…case 结构中的任意位置 default 标签不是必选的,但使用 default 标签是一个良好的编程习惯 每两个 case 标签之间的语句数不限 switch…case 语法: switch (选择变量) { case 值1: … break; case 值2: … break; case 值3: … break; ... ... default : … } 例 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace @switch._._.@case { class Program { static void Main(string[] args) { int i; for(i=0;i10;i++) switch (i) { case 0: Console.WriteLine(i is zero); break; case 1: Console.WriteLine(i is one); break; case 2: Console.WriteLine(i is two); break; case 3: Console.WriteLine(i is three); break; case 4: Console.WriteLine(i is four); break; default: Console.WriteLine(i is five or more); break; } Console.ReadKey(); } } } 输出结果: 三元运算符 condition ? first_expression : second_expression; 三元运算符 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace 三元运算符 { class MainClass { static double sinc(double x) { return

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档