字典Dictionary和泛型集合List的增,删,改,查

            Dictionary<string, int> dic1 = new Dictionary<string, int>();
            dic1.Add("艺龙一楼", 1);
            dic1.Add("艺龙二楼", 2);
            dic1.Add("艺龙三楼", 3);
            //查找
            if (dic1.ContainsKey("艺龙二楼"))
            {
                int i = dic1["艺龙二楼"];
                Response.Write(i);
            }
            dic1.Remove("艺龙二楼");
            Dictionary<string, int> dic2 = dic1.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

            List<string> str = new List<string>();
            str.FindAll(delegate(string st) { return st == "1"; });
            str.RemoveAll(delegate(string sr) { return sr == "1"; });
            str.Sort(delegate(string st1, string st2) { return st1.CompareTo(st2); });

转载于:https://www.cnblogs.com/netbuy/articles/2855175.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 在.NET Framework中,集合是一种用于存储和操作数据的数据结构。集合提供了比数组更灵活和功能更强大的方式来组织和访问数据。集合可以根据需要自动扩展大小,并且可以存储不同类型的数据。与数组不同,集合的长度是动态的,可以根据需要进行调整,这使得集合更加灵活和高效。\[1\] 在.NET Framework中,常用的集合包括ArrayListList<T>、Hashtable、Dictionary<TKey, TValue>、Stack、Queue、SortedList、SortedDictionary、HashSet、SortedSet和LinkedList。每种集合都有其特定的用途和优势。例如,ArrayListList<T>类似于数组,可以按索引访问元素,而Hashtable和Dictionary<TKey, TValue>是键值对集合,可以通过键来访问值。Stack和Queue分别是堆栈和队列集合,SortedSet和SortedDictionary是有序集合,HashSet是无序且不重复的集合,LinkedList是双向链表集合。\[1\] 此外,.NET Framework还提供了ConcurrentDictionary<TKey, TValue>,它是一个线程安全的基于散列的字典,支持并发的多线程读写和线程安全的迭代。它实现了标准的IDictionary<TKey, TValue>接口,并提供了对字典的并发访问的支持。\[2\] 总之,.NET Framework提供了丰富的集合类,可以满足不同的需求。这些集合类可以帮助开发人员更方便地组织和操作数据,提高代码的效率和可读性。\[3\] #### 引用[.reference_title] - *1* [(06)基础强化:ArrayList与Hashtable,比较器Comparer,泛型集合ListDictionary,V>,枚举器与迭代器,泛型的...](https://blog.csdn.net/dzweather/article/details/130544279)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [.NET中的泛型集合](https://blog.csdn.net/kalvin_y_liu/article/details/118640527)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down28v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值