📌  相关文章
📜  C#|检查HybridDictionary是否具有固定大小

📅  最后修改于: 2021-05-29 19:42:05             🧑  作者: Mango

HybridDictionary.IsFixedSize属性用于获取一个值,该值指示HybridDictionary是否具有固定大小。

句法:

public bool IsFixedSize { get; }

返回值:该属性始终返回false

下面的程序说明了HybridDictionary.IsFixedSize属性的使用:

范例1:

// C# code to check whether the
// HybridDictionary has a fixed size.
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating a HybridDictionary named myDict
        HybridDictionary myDict = new HybridDictionary();
  
        // Adding key/value pairs in myDict
        myDict.Add("A", "Apple");
        myDict.Add("B", "Banana");
        myDict.Add("C", "Cat");
        myDict.Add("D", "Dog");
        myDict.Add("E", "Elephant");
        myDict.Add("F", "Fish");
  
        // To check whether the HybridDictionary
        // has a fixed size.
        Console.WriteLine(myDict.IsFixedSize);
    }
}

输出:

False

范例2:

// C# code to check whether the
// HybridDictionary has a fixed size.
using System;
using System.Collections;
using System.Collections.Specialized;
  
class GFG {
  
    // Driver code
    public static void Main()
    {
  
        // Creating a HybridDictionary named myDict
        HybridDictionary myDict = new HybridDictionary();
  
        // Adding key/value pairs in myDict
        myDict.Add("key1", "value1");
        myDict.Add("key2", "value2");
        myDict.Add("key3", "value3");
        myDict.Add("key4", "value4");
  
        // To check whether the HybridDictionary
        // has a fixed size.
        Console.WriteLine(myDict.IsFixedSize);
    }
}

输出:

False

笔记:

  • 具有固定大小的集合不允许在创建集合后添加或删除元素,但是可以修改现有元素。
  • 检索此属性的值是O(1)操作。

参考:

  • https://docs.microsoft.com/zh-cn/dotnet/api/system.collections.specialized.hybriddictionary.isfixedsize?view=netframework-4.7.2