在 C# 中建立空大小寫敏感 HybridDictionary 類


要建立一個空的區分大小寫的 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

更新於: 06-Dec-2019

82 瀏覽量

為你的職業生涯注入活力

透過完成該課程取得認證

開始吧
廣告