1. Ctrl + 右 },可以快速在两个花括号之间跳转
2. C W 连续按下两次Tab键,补齐Console.WriteLine();
3. if 连续按下两次Tab键,补齐 if 语句
4.sw 连续按下两次Tab键,补齐 switch 语句
5. 枚举类型写法:写在class同级
enum Level
{
High,
Mid,
Low
}
枚举类型调用:
Level mylevel = new Level();
switch (mylevel)
{
case Level.High:
Console.WriteLine("High Level");
break;
case Level.Mid:
Console.WriteLine("Mid Level");
break;
case Level.Low:
Console.WriteLine("Low Level");
break;
default:
break;
}
6.while 语句执行0次或多次
int score = 0;
bool canContinue = true;
while (canContinue)
{
Console.WriteLine("Please input first number:");
string str1 = Console.ReadLine();
int x = int.Parse(str1);
Console.WriteLine("Please input second number:");
String str2 = Console.ReadLine();
int y = int.Parse(str2);
int sum = x + y;
if(sum == 100)
{
score++;
Console.WriteLine("Correct!{0}+{1}={2}",x,y,sum);
}
else
{
canContinue = false;
Console.WriteLine("Error!{0}+{1}={2}",x,y,sum);
}
}
Console.WriteLine("Your score is {0}",score);
Console.WriteLine("GAME OVER!");
7.do while 语句,先执行一次do,然后判断while 语句条件是否成立,共执行一次或多次。
int score = 0;
int sum = 0;
do
{
Console.WriteLine("Please input first number:");
string str1 = Console.ReadLine();
int x = int.Parse(str1);
Console.WriteLine("Please input second number:");
String str2 = Console.ReadLine();
int y = int.Parse(str2);
sum = x + y;
if (sum == 100)
{
score++;
Console.WriteLine("Correct!{0}+{1}={2}", x, y, sum);
}
else
{
Console.WriteLine("Error!{0}+{1}={2}", x, y, sum);
}
}while (sum == 100);
Console.WriteLine("Your score is {0}",score);
Console.WriteLine("GAME OVER!");
8.continue 语句放弃当前循环,重新开始
break 语句结束循环语句,循环体不再执行,执行循环体之后的语句
9. foreach语句最佳应用场合,对集合进行遍历
int[] myarray = new int[] { 0, 1, 2, 3, 4, 5 };
//foreach 指月,最佳应用场合对集合进行遍历
foreach (var current in myarray)
{
Console.WriteLine(current);
}