首页 文章资讯内容详情

C#中创建一个空的区分大小写的HybridDictionary类

2026-06-04 1 花语

要创建一个空的区分大小写的HybridDictionary,代码如下-

示例

using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary dict = new HybridDictionary(false); dict.Add("A", "AB"); dict.Add("B", "BC"); dict.Add("C", "DE"); dict.Add("D", "de"); Console.WriteLine("Key/Value pairs..."); foreach(DictionaryEntry de in dict) Console.WriteLine("Key = "+de.Key + ", Value = " + de.Value); } }

输出结果

这将产生以下输出-

Key/Value pairs... Key = A, Value = AB Key = B, Value = BC Key = C, Value = DE Key = D, Value = de

示例

让我们看另一个例子-

using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main() { HybridDictionary dict = new HybridDictionary(true); dict.Add("A", "AB"); dict.Add("B", "BC"); dict.Add("C", "DE"); dict.Add("D", "de"); dict.Add("e", "FG"); dict.Add("F", "gh"); Console.WriteLine("Key/Value pairs..."); foreach(DictionaryEntry de in dict) Console.WriteLine("Key = "+de.Key + ", Value = " + de.Value); } }

输出结果

这将产生以下输出-

Key/Value pairs... Key = A, Value = AB Key = B, Value = BC Key = C, Value = DE Key = D, Value = de Key = e, Value = FG Key = F, Value = gh