c#入门笔记1,2020.3.4

数据类型

整形

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); \\将字符串转为intint 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);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值