关于ArrayList,Hashtable,Stack等基础学习

    ArrayList, Hashtable, StortedList和Stack都位于System.Collections空间下:
其中ArrayList不固定大小的对象数组,按照索引访问。Hashtable是键/值队的集合,依据键的哈希代码进行组织,按照键来访问。StortedList存入的元素会自动按照键进行排序,可以按照所以或者键来访问;Stack先进后出的对象集合。
exam:
    ArrayList:有Add(),Remove(),GetValues()等方法
    遍历操作:for(int i=0;i<list.Count;i++)
        {
            Console.WriteLine("第{0}个元素{1}",i+1,list[i]);
        }
    Hashtable:
    遍历操作:foreach(DictionaryEntry de in list)
        {
            Console.WriteLine("键{0}----值{1}",de.Key,de.Value);
        }
    SortedList:
    遍历操作:for(int i=0;i<list.Count;i++)
        {
           Console.WriteLine("键{0}----值{1}",list.GetKey(i),list.GetByIndex(i));
       }  
    或者    
        foreach(DictionaryEntry de in list)
        {
            Console.WriteLine("键{0}>>>>值{1}",de.Key,de.Value);
        }
    Stack:Push(),Pop()方法
    遍历操作:foreach(object o in list)
        {
            Console.WriteLine("元素{0}",o);
        }
.net2.0框架引入了泛型的概念,提供各种泛型集合代替普通集合,简单对应;
 普通集合  泛型集合
 ArrayList  List<T>
 Stack Stack<T> 
 Queue Queue<T> 
 DictionaryEntry KeyValuePair<T> 
 Hashtable Dictionary<T> 
 Comparer Comparer<T> 
注:以上内容参考<asp.net第一步>,朱晔编


posted @ 2007-11-02 15:32  范文轩  阅读(456)  评论(0编辑  收藏  举报