数据类型
整形
int 32bit
long 64bit
浮点型
float 32bit
double 64bit
decimal 128bit
字符串
char ’ ’
string " "
转义字符
\n 换行
\t tab
\ 斜杠
" 双引号
@" " 使句中转义符失效
字面值
整形为int,浮点型为double
隐式类型var
var sb = 1;
sb会自适应为int型;
特殊写法
指数写法(E) 例 2E3 = 2000
十六进制写法(0xf)例 0xff = 255
int a = int.MaxValue; \\置为int的最大值
类型转换
int a;
long b;
a = (int)b;
输入输出
System.Console.WriteLine();
System.Console.Write();
System.Console.ReadLine();
System.Console.Read();
write加line换行,read默认入为int,readline默认读入为string。
常用的字符串方法
不可变性(返回新字符串)
string类与stringbuilder类,stringbuilder拥有更高的效率。
str = str.ToUpper(); \\将小写变为大写
str = string.Empty(); \\将str置为空
string.Empty()不同于null
字符串转换 Parse,TryParse,ToString
string str;
int a = int.Parse(str); \\将字符串转为int型
int c;
bool b = int.TryParse(str, c); \\如果能成功转换,则转换至c中,返回true到b;若不能,返回false到b
int d;
string f = int.ToString(d); \\将int型转化为字符串
计时器(测试程序运行时间)
using System.Dignostics;
…………
Stopwatch 计时器 = new Stopwath();
计时器.Start();
……………
计时器.Stop();
System.Console.WriteLine(计时器.ElapsedMilliseconds);