1. C#从键盘上获取值
//可以获取一连串的字符
string name = Console.ReadLine();
//获取一个字符 只能一个字符 注意:和ReadLine不同
//输入后不用回车
//注意和Console.ReadKey()区分
char sex = Console.ReadKey().KeyChar;
//通过Read获取的是对应的ASSCLL
//比如输入2得到的是50
//输入a 得到的是97
int age = Console.Read();
2.对获取的值处理成整数
string age = Console.ReadLine();
int age1 = int.Parse(age);
//常用第二种 对大部分不同获取值得类型都能进行转变
int age2 = Convert.ToInt32(Console.ReadLine());
3.常见转译字符
//@符号可以吧\和空格都打印出来
string path = @"F:\Visual Studio\workSpace";
Console.WriteLine(@"F:\Visual Studio\workSpace");
Console.WriteLine(@"今天天气好
确实好");
\\ 双\\表示一个\
string path1 = "F:\\Visual Studio\\workSpace";
4.Try catch异常捕获
int number =0;
Console.WriteLine("请输入的你数字");
try
{
//number 要在外部声明,在里面声明的话是局部变量
number = Convert.ToInt32(Console.ReadLine());
}
catch
{
//抛出异常的话就执行catch里面的语句
Console.WriteLine("请输入类型有误");
}
Console.WriteLine(number*2);
Console.ReadKey();
5.break和continue
break终止循环
continue跳过这次循环进入到下一次循环