C# | Compruebe si HybridDictionary tiene un tamaño fijo

La propiedad HybridDictionary.IsFixedSize se usa para obtener un valor que indica si HybridDictionary tiene un tamaño fijo o no.

Sintaxis:

public bool IsFixedSize { get; }

Valor devuelto: esta propiedad siempre devuelve falso .

A continuación se muestran los programas para ilustrar el uso de la propiedad HybridDictionary.IsFixedSize :

Ejemplo 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);
    }
}

Producción:

False

Ejemplo 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);
    }
}

Producción:

False

Nota:

  • Una colección con un tamaño fijo no permite la adición o eliminación de elementos después de crear la colección, pero permite la modificación de elementos existentes.
  • Recuperar el valor de esta propiedad es una operación O(1) .

Referencia:

Publicación traducida automáticamente

Artículo escrito por Sahil_Bansall y traducido por Barcelona Geeks. The original can be accessed here. Licence: CCBY-SA

Deja una respuesta

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *