CollectionsUtil 类

CreateCaseInsensitiveHashtable()创建 Hashtable 类具有默认初始容量的不区分大小写的新实例。
公共方法静态成员CreateCaseInsensitiveHashtable(IDictionary)将项从指定字典复制到 Hashtable 类的不区分大小写的新实例,该实例具有与复制项的数量相同的初始容量。
公共方法静态成员CreateCaseInsensitiveHashtable(Int32)创建 Hashtable 类具有指定初始容量的不区分大小写的新实例。
公共方法静态成员CreateCaseInsensitiveSortedList创建 SortedList 类的新实例,该实例忽略字符串的大小写。
公共方法Equals(Object)确定指定的对象是否等于当前对象。 (继承自 Object。)
受保护的方法Finalize允许对象在“垃圾回收”回收之前尝试释放资源并执行其他清理操作。 (继承自 Object。)
公共方法GetHashCode用作特定类型的哈希函数。 (继承自 Object。)
公共方法GetType获取当前实例的 Type (继承自 Object。)
受保护的方法MemberwiseClone创建当前 Object 的浅表副本。 (继承自 Object。)
公共方法ToString返回表示当前对象的字符串。 (继承自 Object。)

 

using System;
using System.Collections;
using System.Collections.Specialized;

class TestCollectionsUtils
{
    public static void Main()
    {
        Hashtable population1 = CollectionsUtil.CreateCaseInsensitiveHashtable();

        population1["Trapperville"] = 15;
        population1["Doggerton"] = 230;
        population1["New Hollow"] = 1234;
        population1["McHenry"] = 185;

        // Select cities from the table using mixed case.
        Console.WriteLine("Case insensitive hashtable results:\n");
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population1["trapperville"]);
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population1["DOGGERTON"]);
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population1["New hoLLow"]);
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population1["MchenrY"]);

        SortedList population2 = CollectionsUtil.CreateCaseInsensitiveSortedList();

        foreach (string city in population1.Keys)
        {
           population2.Add(city, population1[city]);
        }

        // Select cities from the sorted list using mixed case.
        Console.WriteLine("\nCase insensitive sorted list results:\n");
        Console.WriteLine("{0}'s population is: {1}", "Trapperville", population2["trapPeRVille"]);
        Console.WriteLine("{0}'s population is: {1}", "Doggerton", population2["dOGGeRtON"]);
        Console.WriteLine("{0}'s population is: {1}", "New Hollow", population2["nEW hOLLOW"]);
        Console.WriteLine("{0}'s population is: {1}", "McHenry", population2["MchEnrY"]);
    }
}

 

转载于:https://www.cnblogs.com/fulai/p/3334331.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值