📌  相关文章
📜  C#|创建一个具有指定大小写敏感性的空HybridDictionary

📅  最后修改于: 2021-05-29 20:58:25             🧑  作者: Mango

HybridDictionary(Boolean)构造函数创建一个空的HybridDictionary,具有指定的区分大小写。

句法:

public HybridDictionary (bool caseInsensitive);

在这里, caseInsensitive是一个布尔值,指示HybridDictionary是否不区分大小写。

下面给出了一些示例,以更好地理解实现:

范例1:

// C# code to create an empty
// HybridDictionary with the
// specified case sensitivity.
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating an empty HybridDictionary
        // with the specified case sensitivity.
        HybridDictionary myDict = new HybridDictionary(false);
  
        // Adding key/value pairs in myDict
        myDict.Add("I", "first");
        myDict.Add("i", "first");
        myDict.Add("II", "second");
        myDict.Add("III", "third");
        myDict.Add("IV", "fourth");
        myDict.Add("V", "fifth");
  
        // Displaying the key/value pairs in myDict
        foreach(DictionaryEntry de in myDict)
            Console.WriteLine(de.Key + " " + de.Value);
    }
}

输出:

I first
i first
II second
III third
IV fourth
V fifth

范例2:

// C# code to create an empty
// HybridDictionary with the
// specified case sensitivity.
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating an empty HybridDictionary
        // with the specified case sensitivity.
        HybridDictionary myDict = new HybridDictionary(true);
  
        // Adding key/value pairs in myDict
        myDict.Add("A", "Apple");
        myDict.Add("a", "Air");
        myDict.Add("B", "Banana");
        myDict.Add("C", "Cat");
        myDict.Add("D", "Dog");
        myDict.Add("d", "Dolphine");
        myDict.Add("E", "Elephant");
        myDict.Add("F", "Fish");
  
        // Displaying the key/value pairs in myDict
        foreach(DictionaryEntry de in myDict)
            Console.WriteLine(de.Key + " " + de.Value);
    }
}

运行时错误:

注意:此构造函数是O(1)操作。