ArrayList,List,HashTable,Dictionary的应用
2008-04-26 14:20
183 查看
ArrayList的应用:
ArrayList list = new ArrayList();
for (int i = 0; i < 3;i++ )
{
student s1 = new student();
s1.Name = ""+i;
s1.Age = 2 - i;
list.Add(s1);
}
for (int i = 0; i < list.Count;i++ )
{
MessageBox.Show(string.Format("姓名为:{0}",((student)list[i]).Name));
}
foreach(Object obj in list)
{
MessageBox.Show(string.Format("年龄为:{0}",((student)obj).Age));
}
HashTable的应用:
Hashtable hs = new Hashtable();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
hs.Add(s1.Name,s1.Age);
}
foreach (Object obj in hs.Keys)
{
MessageBox.Show(string.Format("姓名为:{0}", obj));
}
foreach (Object obj in hs.Values)
{
MessageBox.Show(string.Format("年龄为:{0}", obj));
}
List<obj>的应用:
List<student> list = new List<student>();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
list.Add(s1);
}
for (int i = 0; i < list.Count; i++)
{
MessageBox.Show(string.Format("姓名为:{0}", list[i].Name));
}
foreach (student s1 in list)
{
MessageBox.Show(string.Format("年龄为:{0}", s1.Age));
}
Dictionary<key,obj>的应用:
Dictionary<string,student> d1 = new Dictionary<string,student>();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
d1.Add(s1.Name, s1);
}
foreach (string name in d1.Keys)
{
MessageBox.Show(string.Format("姓名为:{0}",name ));
}
foreach (student s1 in d1.Values)
{
MessageBox.Show(string.Format("年龄为:{0}", s1.Age));
}
ArrayList list = new ArrayList();
for (int i = 0; i < 3;i++ )
{
student s1 = new student();
s1.Name = ""+i;
s1.Age = 2 - i;
list.Add(s1);
}
for (int i = 0; i < list.Count;i++ )
{
MessageBox.Show(string.Format("姓名为:{0}",((student)list[i]).Name));
}
foreach(Object obj in list)
{
MessageBox.Show(string.Format("年龄为:{0}",((student)obj).Age));
}
HashTable的应用:
Hashtable hs = new Hashtable();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
hs.Add(s1.Name,s1.Age);
}
foreach (Object obj in hs.Keys)
{
MessageBox.Show(string.Format("姓名为:{0}", obj));
}
foreach (Object obj in hs.Values)
{
MessageBox.Show(string.Format("年龄为:{0}", obj));
}
List<obj>的应用:
List<student> list = new List<student>();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
list.Add(s1);
}
for (int i = 0; i < list.Count; i++)
{
MessageBox.Show(string.Format("姓名为:{0}", list[i].Name));
}
foreach (student s1 in list)
{
MessageBox.Show(string.Format("年龄为:{0}", s1.Age));
}
Dictionary<key,obj>的应用:
Dictionary<string,student> d1 = new Dictionary<string,student>();
for (int i = 0; i < 3; i++)
{
student s1 = new student();
s1.Name = "" + i;
s1.Age = 2 - i;
d1.Add(s1.Name, s1);
}
foreach (string name in d1.Keys)
{
MessageBox.Show(string.Format("姓名为:{0}",name ));
}
foreach (student s1 in d1.Values)
{
MessageBox.Show(string.Format("年龄为:{0}", s1.Age));
}
相关文章推荐
- C# 集合类总结 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue 泛型
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- 泛型与非泛型集合类的区别及使用例程,包括ArrayList,Hashtable,List<T>,Dictionary<Tkey,Tvalue>,SortedList<Tkey,Tvalue>,Queu
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- c#中List、Dictionary、ArrayList、Hashtable和数组的区别
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- [C#]泛型与非泛型集合类的区别及使用例程,包括ArrayList,Hashtable,List<T>,Dictionary<Tkey,Tvalue>,SortedList<Tkey,Tvalue>,Queue<T>,Stack<T>等
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 Array Arraylist List Hashtable Dictionary Stack Queue
- C# 集合类 Array,Arraylist,List,Hashtable,Dictionary,Stack,Queue学习资...
- C# 集合类 :(Array、 Arraylist、List、Hashtable、Dictionary、Stack、Queue)
- ArrayList、HashSet、HashTable、List、Dictionary的区别
- C#使用集合组织数据(HashTable、ArrayList、List<T>,Dictionary<K,V>
- C#中的集合ArrayList、List、Hashtable、Dictionary
- C#集合的區別(Array、Arraylist、 List、 Hashtable、SortedList、 Dictionary、 Stack、 Queue )