.net学习第十三天小结 泛型集合,装箱拆箱,键值对集合,FileStream,多态

1.泛型集合List:确定了集合元素的类型,不进行装箱拆箱.

2.装箱:将值类型装换为引用类型.

拆箱:将引用类型装换为值类型

尽量避免装箱拆箱.

3.键值对集合:Dictionary<int ,string> dic =new Dictionary<int,string>();

dic.Add(1,"张三");

dic[2]="李四";

两种方法添加,键相同时,第一种方法抛异常,第二种覆盖.

遍历用

 foreach(keyValuePair<int,string> kv in dic ){

kv.key;

kv.value; 

}

4.File FileStream StreamReader StreamWriter  :命名空间IO

FileStream:操作字节

StreamReader StreamWriter:操作字符

//读文件,using:自动回收资源

using(FileStream fsRead= new FileStream(".txt",FileMode.OpenOrCreate,FileAcess.Read)){

byte[] buffer=new byte[1024*1024*5];

//本次读取实际读取的字节数

int r=fsRead.Read(buffer,0,buffer.Length);

将字节数组中的每个元素按照我们指定的编码格式解析成字符串

string s =Encoding.Default.GetString(buffer,0,r);

}

//写文件

using(FileStream fsWrite= new FileStream(@".txt",FileMode.OpenOrCreate,FileAcess.Write)){

string s="写的东西";

byte[] buffer =Encoding.Default.GetBytes(s);

fsWrite.Write(buffer ,0,buffer.Length );

//本次读取实际读取的字节数

int r=fsRead.Read(buffer,0,buffer.Length);

将字节数组中的每个元素按照我们指定的编码格式解析成字符串

string s =Encoding.Default.GetString(buffer,0,r);

}

5.多态:一个对象表现多个类型

虚方法和抽象类

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值