C# 面向对象系列笔记(四)
第四天
1.泛型集合
1>ArrayList--->List<T> 集合
-àlist.Add() //添加数据
-àlist.AddRange(new int[]{1,2,3,4,5,7,8,9});//添加集合数据
-àlist.Chera(); //清除所有数据
-àlist.Reverse(); //翻转;
-àlist.Sort(); //升序排列
-àIist.Insert(0,100); //根据索引添加数据
-àlist.Insert(0,new int[]{1,2,3,4,5.67});
-àlist.Remove(100); //写谁 谁删除
-àlist.RemoveAt(5); //根据索引删除
-àlist.RemoveRange(1,10); //删除一段;1,开始索引,10: 移除的范围
-àlist.RemoveAll(n=>n>3); //lamda表达式
2>Hashtable--->Dictionary<Tkey,Tvalue> 键值对集合
遍历方式:
// 循环输出键值对集合
foreach (var item in dic.Keys)
{
Console.WriteLine("键{0}----值{1}",item,dic[item]);
}
//更加洋气的遍历方式
foreach (KeyValuePair<string, int> kvp in dic)
{
Console.WriteLine("键{0}---值{1}", kvp.Key, kvp.Value);
}
2.File读写数据(上接昨天讲的File)
1> ReadAllBytes(): 以字节的形式读取文件
eg:
温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/70173.html
- 上一篇:C# 面向对象系列笔记(二)
- 下一篇:不需要密码的windows计划任务设置