您的位置:首页 > 编程语言 > C#

c#基础4

2015-11-02 16:11 465 查看
1.集合的复习

namespace 集合的复习2
{
class Program
{
static void
4000
Main(string[] args)
{
//集合 ArrayList Hashtable
//List<T> Dictionary<TKey,TValue>
//装箱:值类型转为引用类型
//拆箱:引用类型转为值类型
//拆装箱的两种类型必须有继承关系
//值类型:bool int double char struct enum decimal 存贮在栈中 传递值得本身
//引用类型:string 数组 集合 interface object 自定义类 存储在堆中 传递值得引用(地址??)
//ref:将值传递变成引用传递
ArrayList list = new ArrayList();
//list.Add();
Hashtable ht = new Hashtable();
//ht.Add();

List<int> list = new List<int>();
//list.Add();添加单个元素
//list.AddRange();添加集合
//list.Insert();插入
//list.InsertRange();插入集合
//list.Remove();
//list.RemoveAt();
//list.RemoveRange();
//list.Contains();判断是否包含
//list.RemoveAll();

Dictionary<int, string> dic = new Dictionary<int, string>();
dic.Add(1,"kyle");
dic.Add(2, "nestle");//添加相同的值会抛异常,可以通过下标重新赋值
dic.Add(3, "kitty");
dic[3] = "kaka";

//遍历元素多用foreach
foreach (KeyValuePair<int,string> kv in dic)
{
Console.WriteLine("{0}----{1}",kv.Key,kv.Value);
}
Console.ReadKey();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: