泛型集合
单列集合
List<t>list=new List<t>();
双列集合
不能用for循环遍历,因为双列集合没有下标索引值
Dictionary<string,Student> dic=new Dictionary<string,Student>();
dic.add("张三",stu1);
dic.add("李四",stu2);
//1种
foreach(string item in dic.Keys)
{
Student stu=dic[item];
}
//第二种
foreach(Student item in dic.Values)
{
Student stu=dic[item];
}
//第三种
}
foreach(KeyValuePair<string,Student> item in dic)
{
//item=key+Value
item.Key
item.Value
}
单列集合数据绑定
List<UserInfo> list;
dgvList.DataSource=new BindingList<UserInfo>(list);
双列集合数据绑定
Dictionary<string,Student> dic=new Dictionary<string,Student>();
BindingSource bs=new BindingSource();
bs.DataSource=dic.Values;
dgvList.DataSource=bs;