NameObjectCollectionBase Class

Definition

Proporciona la clase base abstract de una colección de claves de String y valores de Object asociados a los que se puede obtener acceso con la clave o con el índice.Provides the abstract base class for a collection of associated String keys and Object values that can be accessed either with the key or with the index.

public ref class NameObjectCollectionBase abstract : System::Collections::ICollection
public ref class NameObjectCollectionBase abstract : System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
public abstract class NameObjectCollectionBase : System.Collections.ICollection
public abstract class NameObjectCollectionBase : System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public abstract class NameObjectCollectionBase : System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
type NameObjectCollectionBase = class
    interface ICollection
    interface IEnumerable
type NameObjectCollectionBase = class
    interface ICollection
    interface IEnumerable
    interface IDeserializationCallback
    interface ISerializable
type NameObjectCollectionBase = class
    interface ICollection
    interface IEnumerable
    interface ISerializable
    interface IDeserializationCallback
type NameObjectCollectionBase = class
    interface ICollection
    interface ISerializable
    interface IDeserializationCallback
    interface IEnumerable
Public MustInherit Class NameObjectCollectionBase
Implements ICollection
Public MustInherit Class NameObjectCollectionBase
Implements ICollection, IDeserializationCallback, ISerializable
Inheritance
NameObjectCollectionBase
Derived
Attributes
Implements

Examples

En el ejemplo de código siguiente se muestra cómo implementar y utilizar la clase NameObjectCollectionBase.The following code example shows how to implement and use the NameObjectCollectionBase class.

#using <System.dll>
using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;

public ref class MyCollection : public NameObjectCollectionBase  {

private:
   DictionaryEntry^ _de;

   // Creates an empty collection.
public:
   MyCollection()  {
      _de = gcnew DictionaryEntry();
   }

   // Adds elements from an IDictionary into the new collection.
   MyCollection( IDictionary^ d, Boolean bReadOnly )  {

      _de = gcnew DictionaryEntry();

      for each ( DictionaryEntry^ de in d )  {
         this->BaseAdd( (String^) de->Key, de->Value );
      }
      this->IsReadOnly = bReadOnly;
   }

   // Gets a key-and-value pair (DictionaryEntry) using an index.
   property DictionaryEntry^ default[ int ]  {
      DictionaryEntry^ get(int index)  {
         _de->Key = this->BaseGetKey(index);
         _de->Value = this->BaseGet(index);
         return( _de );
      }
   }

   // Gets or sets the value associated with the specified key.
   property Object^ default[ String^ ]  {
      Object^ get(String^ key)  {
         return( this->BaseGet( key ) );
      }
      void set( String^ key, Object^ value )  {
         this->BaseSet( key, value );
      }
   }

   // Gets a String array that contains all the keys in the collection.
   property array<String^>^ AllKeys  {
      array<String^>^ get()  {
         return( (array<String^>^)this->BaseGetAllKeys() );
      }
   }

   // Gets an Object array that contains all the values in the collection.
   property Array^ AllValues  {
      Array^ get()  {
         return( this->BaseGetAllValues() );
      }
   }

   // Gets a String array that contains all the values in the collection.
   property array<String^>^ AllStringValues  {
      array<String^>^ get()  {
         return( (array<String^>^) this->BaseGetAllValues(  String ::typeid ));
      }
   }

   // Gets a value indicating if the collection contains keys that are not null.
   property Boolean HasKeys  {
      Boolean get()  {
         return( this->BaseHasKeys() );
      }
   }

   // Adds an entry to the collection.
   void Add( String^ key, Object^ value )  {
      this->BaseAdd( key, value );
   }

   // Removes an entry with the specified key from the collection.
   void Remove( String^ key )  {
      this->BaseRemove( key );
   }

   // Removes an entry in the specified index from the collection.
   void Remove( int index )  {
      this->BaseRemoveAt( index );
   }

   // Clears all the elements in the collection.
   void Clear()  {
      this->BaseClear();
   }
};

public ref class SamplesNameObjectCollectionBase  {

public:
   static void Main()  {
      // Creates and initializes a new MyCollection that is read-only.
      IDictionary^ d = gcnew ListDictionary();
      d->Add( "red", "apple" );
      d->Add( "yellow", "banana" );
      d->Add( "green", "pear" );
      MyCollection^ myROCol = gcnew MyCollection( d, true );

      // Tries to add a new item.
      try  {
         myROCol->Add( "blue", "sky" );
      }
      catch ( NotSupportedException^ e )  {
         Console::WriteLine( e->ToString() );
      }

      // Displays the keys and values of the MyCollection.
      Console::WriteLine( "Read-Only Collection:" );
      PrintKeysAndValues( myROCol );

      // Creates and initializes an empty MyCollection that is writable.
      MyCollection^ myRWCol = gcnew MyCollection();

      // Adds new items to the collection.
      myRWCol->Add( "purple", "grape" );
      myRWCol->Add( "orange", "tangerine" );
      myRWCol->Add( "black", "berries" );
      Console::WriteLine( "Writable Collection (after adding values):" );
      PrintKeysAndValues( myRWCol );

      // Changes the value of one element.
      myRWCol["orange"] = "grapefruit";
      Console::WriteLine( "Writable Collection (after changing one value):" );
      PrintKeysAndValues( myRWCol );

      // Removes one item from the collection.
      myRWCol->Remove( "black" );
      Console::WriteLine( "Writable Collection (after removing one value):" );
      PrintKeysAndValues( myRWCol );

      // Removes all elements from the collection.
      myRWCol->Clear();
      Console::WriteLine( "Writable Collection (after clearing the collection):" );
      PrintKeysAndValues( myRWCol );
   }

   // Prints the indexes, keys, and values.
   static void PrintKeysAndValues( MyCollection^ myCol )  {
      for ( int i = 0; i < myCol->Count; i++ )  {
         Console::WriteLine( "[{0}] : {1}, {2}", i, myCol[i]->Key, myCol[i]->Value );
      }
   }

   // Prints the keys and values using AllKeys.
   static void PrintKeysAndValues2( MyCollection^ myCol )  {
      for each ( String^ s in myCol->AllKeys )  {
         Console::WriteLine( "{0}, {1}", s, myCol[s] );
      }
   }
};

int main()
{
    SamplesNameObjectCollectionBase::Main();
}

/*
This code produces the following output.

System.NotSupportedException: Collection is read-only.
   at System.Collections.Specialized.NameObjectCollectionBase.BaseAdd(String name, Object value)
   at SamplesNameObjectCollectionBase.Main()
Read-Only Collection:
[0] : red, apple
[1] : yellow, banana
[2] : green, pear
Writable Collection (after adding values):
[0] : purple, grape
[1] : orange, tangerine
[2] : black, berries
Writable Collection (after changing one value):
[0] : purple, grape
[1] : orange, grapefruit
[2] : black, berries
Writable Collection (after removing one value):
[0] : purple, grape
[1] : orange, grapefruit
Writable Collection (after clearing the collection):

*/
using System;
using System.Collections;
using System.Collections.Specialized;

public class MyCollection : NameObjectCollectionBase
{
   // Creates an empty collection.
   public MyCollection()  {
   }

   // Adds elements from an IDictionary into the new collection.
   public MyCollection( IDictionary d, Boolean bReadOnly )  {
      foreach ( DictionaryEntry de in d )  {
         this.BaseAdd( (String) de.Key, de.Value );
      }
      this.IsReadOnly = bReadOnly;
   }

   // Gets a key-and-value pair (DictionaryEntry) using an index.
   public DictionaryEntry this[ int index ]  {
      get  {
          return ( new DictionaryEntry(
              this.BaseGetKey(index), this.BaseGet(index) ) );
      }
   }

   // Gets or sets the value associated with the specified key.
   public Object this[ String key ]  {
      get  {
         return( this.BaseGet( key ) );
      }
      set  {
         this.BaseSet( key, value );
      }
   }

   // Gets a String array that contains all the keys in the collection.
   public String[] AllKeys  {
      get  {
         return( this.BaseGetAllKeys() );
      }
   }

   // Gets an Object array that contains all the values in the collection.
   public Array AllValues  {
      get  {
         return( this.BaseGetAllValues() );
      }
   }

   // Gets a String array that contains all the values in the collection.
   public String[] AllStringValues  {
      get  {
         return( (String[]) this.BaseGetAllValues( typeof( string ) ));
      }
   }

   // Gets a value indicating if the collection contains keys that are not null.
   public Boolean HasKeys  {
      get  {
         return( this.BaseHasKeys() );
      }
   }

   // Adds an entry to the collection.
   public void Add( String key, Object value )  {
      this.BaseAdd( key, value );
   }

   // Removes an entry with the specified key from the collection.
   public void Remove( String key )  {
      this.BaseRemove( key );
   }

   // Removes an entry in the specified index from the collection.
   public void Remove( int index )  {
      this.BaseRemoveAt( index );
   }

   // Clears all the elements in the collection.
   public void Clear()  {
      this.BaseClear();
   }
}

public class SamplesNameObjectCollectionBase  {

   public static void Main()  {

      // Creates and initializes a new MyCollection that is read-only.
      IDictionary d = new ListDictionary();
      d.Add( "red", "apple" );
      d.Add( "yellow", "banana" );
      d.Add( "green", "pear" );
      MyCollection myROCol = new MyCollection( d, true );

      // Tries to add a new item.
      try  {
         myROCol.Add( "blue", "sky" );
      }
      catch ( NotSupportedException e )  {
         Console.WriteLine( e.ToString() );
      }

      // Displays the keys and values of the MyCollection.
      Console.WriteLine( "Read-Only Collection:" );
      PrintKeysAndValues( myROCol );

      // Creates and initializes an empty MyCollection that is writable.
      MyCollection myRWCol = new MyCollection();

      // Adds new items to the collection.
      myRWCol.Add( "purple", "grape" );
      myRWCol.Add( "orange", "tangerine" );
      myRWCol.Add( "black", "berries" );
      Console.WriteLine( "Writable Collection (after adding values):" );
      PrintKeysAndValues( myRWCol );

      // Changes the value of one element.
      myRWCol["orange"] = "grapefruit";
      Console.WriteLine( "Writable Collection (after changing one value):" );
      PrintKeysAndValues( myRWCol );

      // Removes one item from the collection.
      myRWCol.Remove( "black" );
      Console.WriteLine( "Writable Collection (after removing one value):" );
      PrintKeysAndValues( myRWCol );

      // Removes all elements from the collection.
      myRWCol.Clear();
      Console.WriteLine( "Writable Collection (after clearing the collection):" );
      PrintKeysAndValues( myRWCol );
   }

   // Prints the indexes, keys, and values.
   public static void PrintKeysAndValues( MyCollection myCol )  {
      for ( int i = 0; i < myCol.Count; i++ )  {
         Console.WriteLine( "[{0}] : {1}, {2}", i, myCol[i].Key, myCol[i].Value );
      }
   }

   // Prints the keys and values using AllKeys.
   public static void PrintKeysAndValues2( MyCollection myCol )  {
      foreach ( String s in myCol.AllKeys )  {
         Console.WriteLine( "{0}, {1}", s, myCol[s] );
      }
   }
}


/*
This code produces the following output.

System.NotSupportedException: Collection is read-only.
   at System.Collections.Specialized.NameObjectCollectionBase.BaseAdd(String name, Object value)
   at SamplesNameObjectCollectionBase.Main()
Read-Only Collection:
[0] : red, apple
[1] : yellow, banana
[2] : green, pear
Writable Collection (after adding values):
[0] : purple, grape
[1] : orange, tangerine
[2] : black, berries
Writable Collection (after changing one value):
[0] : purple, grape
[1] : orange, grapefruit
[2] : black, berries
Writable Collection (after removing one value):
[0] : purple, grape
[1] : orange, grapefruit
Writable Collection (after clearing the collection):

*/
Imports System.Collections
Imports System.Collections.Specialized

Public Class MyCollection
   Inherits NameObjectCollectionBase

   ' Creates an empty collection.
   Public Sub New()
   End Sub

   ' Adds elements from an IDictionary into the new collection.
   Public Sub New(d As IDictionary, bReadOnly As Boolean)
      Dim de As DictionaryEntry
      For Each de In  d
         Me.BaseAdd(CType(de.Key, String), de.Value)
      Next de
      Me.IsReadOnly = bReadOnly
   End Sub

   ' Gets a key-and-value pair (DictionaryEntry) using an index.
   Default Public ReadOnly Property Item(index As Integer) As DictionaryEntry
      Get
            return new DictionaryEntry( _
                me.BaseGetKey(index), me.BaseGet(index) )
      End Get
   End Property

   ' Gets or sets the value associated with the specified key.
   Default Public Property Item(key As String) As Object
      Get
         Return Me.BaseGet(key)
      End Get
      Set
         Me.BaseSet(key, value)
      End Set
   End Property

   ' Gets a String array that contains all the keys in the collection.
   Public ReadOnly Property AllKeys() As String()
      Get
         Return Me.BaseGetAllKeys()
      End Get
   End Property

   ' Gets an Object array that contains all the values in the collection.
   Public ReadOnly Property AllValues() As Array
      Get
         Return Me.BaseGetAllValues()
      End Get
   End Property

   ' Gets a String array that contains all the values in the collection.
   Public ReadOnly Property AllStringValues() As String()
      Get
         Return CType(Me.BaseGetAllValues(GetType(String)), String())
      End Get
   End Property

   ' Gets a value indicating if the collection contains keys that are not null.
   Public ReadOnly Property HasKeys() As Boolean
      Get
         Return Me.BaseHasKeys()
      End Get
   End Property

   ' Adds an entry to the collection.
   Public Sub Add(key As String, value As Object)
      Me.BaseAdd(key, value)
   End Sub

   ' Removes an entry with the specified key from the collection.
   Overloads Public Sub Remove(key As String)
      Me.BaseRemove(key)
   End Sub

   ' Removes an entry in the specified index from the collection.
   Overloads Public Sub Remove(index As Integer)
      Me.BaseRemoveAt(index)
   End Sub

   ' Clears all the elements in the collection.
   Public Sub Clear()
      Me.BaseClear()
   End Sub

End Class


Public Class SamplesNameObjectCollectionBase   

   Public Shared Sub Main()

      ' Creates and initializes a new MyCollection that is read-only.
      Dim d As New ListDictionary()
      d.Add("red", "apple")
      d.Add("yellow", "banana")
      d.Add("green", "pear")
      Dim myROCol As New MyCollection(d, True)

      ' Tries to add a new item.
      Try
         myROCol.Add("blue", "sky")
      Catch e As NotSupportedException
         Console.WriteLine(e.ToString())
      End Try

      ' Displays the keys and values of the MyCollection.
      Console.WriteLine("Read-Only Collection:")
      PrintKeysAndValues(myROCol)

      ' Creates and initializes an empty MyCollection that is writable.
      Dim myRWCol As New MyCollection()

      ' Adds new items to the collection.
      myRWCol.Add("purple", "grape")
      myRWCol.Add("orange", "tangerine")
      myRWCol.Add("black", "berries")
      Console.WriteLine("Writable Collection (after adding values):")
      PrintKeysAndValues(myRWCol)

      ' Changes the value of one element.
      myRWCol("orange") = "grapefruit"
      Console.WriteLine("Writable Collection (after changing one value):")
      PrintKeysAndValues(myRWCol)

      ' Removes one item from the collection.
      myRWCol.Remove("black")
      Console.WriteLine("Writable Collection (after removing one value):")
      PrintKeysAndValues(myRWCol)

      ' Removes all elements from the collection.
      myRWCol.Clear()
      Console.WriteLine("Writable Collection (after clearing the collection):")
      PrintKeysAndValues(myRWCol)

   End Sub

   ' Prints the indexes, keys, and values.
   Public Shared Sub PrintKeysAndValues(myCol As MyCollection)
      Dim i As Integer
      For i = 0 To myCol.Count - 1
         Console.WriteLine("[{0}] : {1}, {2}", i, myCol(i).Key, myCol(i).Value)
      Next i
   End Sub

   ' Prints the keys and values using AllKeys.
   Public Shared Sub PrintKeysAndValues2(myCol As MyCollection)
      Dim s As String
      For Each s In  myCol.AllKeys
         Console.WriteLine("{0}, {1}", s, myCol(s))
      Next s
   End Sub

End Class


'This code produces the following output.
'
'System.NotSupportedException: Collection is read-only.
'   at System.Collections.Specialized.NameObjectCollectionBase.BaseAdd(String name, Object value)
'   at SamplesNameObjectCollectionBase.Main()
'Read-Only Collection:
'[0] : red, apple
'[1] : yellow, banana
'[2] : green, pear
'Writable Collection (after adding values):
'[0] : purple, grape
'[1] : orange, tangerine
'[2] : black, berries
'Writable Collection (after changing one value):
'[0] : purple, grape
'[1] : orange, grapefruit
'[2] : black, berries
'Writable Collection (after removing one value):
'[0] : purple, grape
'[1] : orange, grapefruit
'Writable Collection (after clearing the collection):

Remarks

La estructura subyacente de esta clase es una tabla hash.The underlying structure for this class is a hash table.

Cada elemento es un par clave-valor.Each element is a key/value pair.

La capacidad de una NameObjectCollectionBase es el número de elementos que puede contener el NameObjectCollectionBase.The capacity of a NameObjectCollectionBase is the number of elements the NameObjectCollectionBase can hold. A medida que se agregan elementos a un NameObjectCollectionBase, la capacidad aumenta automáticamente según sea necesario a través de la reasignación.As elements are added to a NameObjectCollectionBase, the capacity is automatically increased as required through reallocation.

El proveedor de código hash dispensará los códigos hash de las claves de la instancia de NameObjectCollectionBase.The hash code provider dispenses hash codes for keys in the NameObjectCollectionBase instance. El proveedor de código hash predeterminado es el CaseInsensitiveHashCodeProvider.The default hash code provider is the CaseInsensitiveHashCodeProvider.

El comparador determina si dos claves son iguales.The comparer determines whether two keys are equal. El comparador predeterminado es el CaseInsensitiveComparer.The default comparer is the CaseInsensitiveComparer.

En .NET Framework versión 1,0, esta clase utiliza comparaciones de cadenas que tienen en cuenta la referencia cultural.In .NET Framework version 1.0, this class uses culture-sensitive string comparisons. Sin embargo, en .NET Framework versión 1,1 y versiones posteriores, esta clase usa CultureInfo.InvariantCulture al comparar cadenas.However, in .NET Framework version 1.1 and later, this class uses CultureInfo.InvariantCulture when comparing strings. Para obtener más información sobre cómo afecta la referencia cultural a las comparaciones y ordenación, vea realizar operaciones de cadenas que no tienen en cuenta las referencias culturales.For more information about how culture affects comparisons and sorting, see Performing Culture-Insensitive String Operations.

null se permite como una clave o como un valor.null is allowed as a key or as a value.

Caution

El método BaseGet no distingue entre null que se devuelve porque la clave especificada no se encuentra y null que se devuelve porque se nullel valor asociado a la clave.The BaseGet method does not distinguish between null which is returned because the specified key is not found and null which is returned because the value associated with the key is null.

Constructors

NameObjectCollectionBase()

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía.Initializes a new instance of the NameObjectCollectionBase class that is empty.

NameObjectCollectionBase(IEqualityComparer)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía, tiene la capacidad inicial predeterminada y usa el objeto IEqualityComparer especificado.Initializes a new instance of the NameObjectCollectionBase class that is empty, has the default initial capacity, and uses the specified IEqualityComparer object.

NameObjectCollectionBase(IHashCodeProvider, IComparer)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía, tiene la capacidad inicial predeterminada y usa el proveedor de código hash y el comparador especificados.Initializes a new instance of the NameObjectCollectionBase class that is empty, has the default initial capacity, and uses the specified hash code provider and the specified comparer.

NameObjectCollectionBase(Int32)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía, tiene la capacidad inicial especificada y usa el proveedor de código hash y el comparador predeterminados.Initializes a new instance of the NameObjectCollectionBase class that is empty, has the specified initial capacity, and uses the default hash code provider and the default comparer.

NameObjectCollectionBase(Int32, IEqualityComparer)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía, tiene la capacidad inicial especificada y usa el objeto IEqualityComparer especificado.Initializes a new instance of the NameObjectCollectionBase class that is empty, has the specified initial capacity, and uses the specified IEqualityComparer object.

NameObjectCollectionBase(Int32, IHashCodeProvider, IComparer)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que está vacía, tiene la capacidad inicial especificada y usa el proveedor de códigos hash y el comparador especificados.Initializes a new instance of the NameObjectCollectionBase class that is empty, has the specified initial capacity and uses the specified hash code provider and the specified comparer.

NameObjectCollectionBase(SerializationInfo, StreamingContext)

Inicializa una nueva instancia de la clase NameObjectCollectionBase que es serializable y usa las clases SerializationInfo y StreamingContext especificadas.Initializes a new instance of the NameObjectCollectionBase class that is serializable and uses the specified SerializationInfo and StreamingContext.

Properties

Count

Obtiene el número de pares de clave y valor incluidos en la instancia NameObjectCollectionBase.Gets the number of key/value pairs contained in the NameObjectCollectionBase instance.

IsReadOnly

Obtiene o establece un valor que indica si la instancia NameObjectCollectionBase es de solo lectura.Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only.

Keys

Obtiene una instancia NameObjectCollectionBase.KeysCollection que contiene todas las claves de la instancia NameObjectCollectionBase.Gets a NameObjectCollectionBase.KeysCollection instance that contains all the keys in the NameObjectCollectionBase instance.

Methods

BaseAdd(String, Object)

Agrega una entrada con la clave y el valor especificados a la instancia NameObjectCollectionBase.Adds an entry with the specified key and value into the NameObjectCollectionBase instance.

BaseClear()

Elimina todas las entradas de la instancia NameObjectCollectionBase.Removes all entries from the NameObjectCollectionBase instance.

BaseGet(Int32)

Obtiene el valor de la entrada que se encuentra en el índice especificado de la instancia NameObjectCollectionBase.Gets the value of the entry at the specified index of the NameObjectCollectionBase instance.

BaseGet(String)

Obtiene el valor de la primera entrada con la clave especificada desde la instancia NameObjectCollectionBase.Gets the value of the first entry with the specified key from the NameObjectCollectionBase instance.

BaseGetAllKeys()

Devuelve una matriz String que contiene todas las claves de la instancia NameObjectCollectionBase.Returns a String array that contains all the keys in the NameObjectCollectionBase instance.

BaseGetAllValues()

Devuelve una matriz Object que contiene todos los valores de la instancia NameObjectCollectionBase.Returns an Object array that contains all the values in the NameObjectCollectionBase instance.

BaseGetAllValues(Type)

Devuelve una matriz del tipo especificado que contiene todos los valores de la instancia NameObjectCollectionBase.Returns an array of the specified type that contains all the values in the NameObjectCollectionBase instance.

BaseGetKey(Int32)

Obtiene la clave de la entrada que se encuentra en el índice especificado de la instancia NameObjectCollectionBase.Gets the key of the entry at the specified index of the NameObjectCollectionBase instance.

BaseHasKeys()

Obtiene un valor que indica si la instancia NameObjectCollectionBase contiene entradas cuyas claves no son null.Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null.

BaseRemove(String)

Quita las entradas con la clave especificada de la instancia de NameObjectCollectionBase.Removes the entries with the specified key from the NameObjectCollectionBase instance.

BaseRemoveAt(Int32)

Elimina la entrada que se encuentra en el índice especificado de la instancia NameObjectCollectionBase.Removes the entry at the specified index of the NameObjectCollectionBase instance.

BaseSet(Int32, Object)

Establece el valor de la entrada que se encuentra en el índice especificado de la instancia NameObjectCollectionBase.Sets the value of the entry at the specified index of the NameObjectCollectionBase instance.

BaseSet(String, Object)

Establece el valor de la primera entrada con la clave especificada de la instancia NameObjectCollectionBase, si la encuentra; en caso contrario, agrega una entrada con la clave y el valor especificados a la instancia NameObjectCollectionBase.Sets the value of the first entry with the specified key in the NameObjectCollectionBase instance, if found; otherwise, adds an entry with the specified key and value into the NameObjectCollectionBase instance.

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetEnumerator()

Devuelve un enumerador que recorre en iteración la colección NameObjectCollectionBase.Returns an enumerator that iterates through the NameObjectCollectionBase.

GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)

Implementa la interfaz de ISerializable y devuelve los datos necesarios para serializar la instancia de NameObjectCollectionBase.Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance.

GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Crea una copia superficial del Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
OnDeserialization(Object)

Implementa la interfaz ISerializable y genera el evento de deserialización cuando esta ha finalizado.Implements the ISerializable interface and raises the deserialization event when the deserialization is complete.

ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

ICollection.CopyTo(Array, Int32)

Copia la totalidad de NameObjectCollectionBase en una matriz Array unidimensional compatible, comenzando en el índice especificado de la matriz de destino.Copies the entire NameObjectCollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

ICollection.IsSynchronized

Obtiene un valor que indica si el acceso al objeto NameObjectCollectionBase está sincronizado (es seguro para subprocesos).Gets a value indicating whether access to the NameObjectCollectionBase object is synchronized (thread safe).

ICollection.SyncRoot

Obtiene un objeto que puede utilizarse para sincronizar el acceso al objeto NameObjectCollectionBase.Gets an object that can be used to synchronize access to the NameObjectCollectionBase object.

Extension Methods

Cast<TResult>(IEnumerable)

Convierte los elementos de IEnumerable en el tipo especificado.Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filtra los elementos de IEnumerable en función de un tipo especificado.Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Habilita la paralelización de una consulta.Enables parallelization of a query.

AsQueryable(IEnumerable)

Convierte una interfaz IEnumerable en IQueryable.Converts an IEnumerable to an IQueryable.

Applies to

Thread Safety

Los miembros estáticos públicos (Shared en Visual Basic) de este tipo son seguros para subprocesos.Public static (Shared in Visual Basic) members of this type are thread safe. No se garantiza que los miembros de instancia sean seguros para subprocesos.Any instance members are not guaranteed to be thread safe.

Esta implementación no proporciona un contenedor sincronizado (seguro para subprocesos) para un NameObjectCollectionBase, pero las clases derivadas pueden crear sus propias versiones sincronizadas de la NameObjectCollectionBase mediante la propiedad SyncRoot.This implementation does not provide a synchronized (thread safe) wrapper for a NameObjectCollectionBase, but derived classes can create their own synchronized versions of the NameObjectCollectionBase using the SyncRoot property.

La enumeración a través de una colección no es intrínsecamente un procedimiento seguro para subprocesos.Enumerating through a collection is intrinsically not a thread safe procedure. Incluso cuando una colección está sincronizada, otros subprocesos todavía pueden modificarla, lo que hace que el enumerador produzca una excepción.Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. Con el fin de garantizar la seguridad para la ejecución de subprocesos durante la enumeración, se puede bloquear la colección durante toda la enumeración o detectar las excepciones resultantes de los cambios realizados por otros subprocesos.To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads.

See also