asp.net泛型集合学习

本文介绍了.NET框架中几种常用集合类,包括ArrayList、Hashtable、SortedList和Stack的基本特性和使用方法,并给出了每种集合类的遍历示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ArrayList, Hashtable, SortedList 和Stack都位于System.Collections空间下:


ArrayList不固定大小的对象数组,按照索引访问。
Hashtable是键/值队的集合,依据键的哈希代码进行组织,按照键来访问。
SortedList 存入的元素会自动按照键进行排序,可以按照所以或者键来访问;
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框架引入了泛型的概念,提供各种泛型集合代替普通集合,简单对应;

普通集合泛型集合
ArrayListList<T>
StackStack<T>
QueueQueue<T>
DictionaryEntryKeyValuePair<T>
HashtableDictionary<T>
ComparerComparer<T>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值