[Serializable] |
This implementation does not provide a synchronized (thread-safe) wrapper for a NameObjectCollectionBase.KeysCollection, but derived classes can create their own synchronized versions of the NameObjectCollectionBase.KeysCollection using the NameObjectCollectionBase.KeysCollection..System.Collections.ICollection.SyncRoot property.
Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. 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.
Count | Read-only Gets the number of keys in the NameObjectCollectionBase.KeysCollection. |
Item | Read-only Gets the entry at the specified index of the collection. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
Get | Gets the key at the specified index of the collection. |
GetEnumerator | Returns an enumerator that can iterate through the NameObjectCollectionBase.KeysCollection. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
ICollection.CopyTo | Copies the entire NameObjectCollectionBase.KeysCollection to a compatible one-dimensional Array, starting at the specified index of the target array. |
Hierarchy:
public int Count {get;}
|
public string this[int index] {get;}
|
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
NotSupportedException | The collection is read-only and the operation attempts to modify the collection. |
myCollection[index]
(In Visual Basic,
myCollection(index)
).
~KeysCollection(); |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
public IEnumerator GetEnumerator(); |
Enumerators only allow reading the data in the collection. Enumerators cannot be used to modify the underlying collection.
Initially, the enumerator is positioned before the first element in the collection. IEnumerator.Reset also brings the enumerator back to this position. At this position, calling IEnumerator.Current throws an exception. Therefore, you must call IEnumerator.MoveNext to advance the enumerator to the first element of the collection before reading the value of IEnumerator.Current.
IEnumerator.Current returns the same object until either IEnumerator.MoveNext or IEnumerator.Reset is called. IEnumerator.MoveNext sets IEnumerator.Current to the next element.
After the end of the collection is passed, the enumerator is positioned after the last element in the collection, and calling IEnumerator.MoveNext returns false. If the last call to IEnumerator.MoveNext returned false, calling IEnumerator.Current throws an exception. To set IEnumerator.Current to the first element of the collection again, you can call IEnumerator.Reset followed by IEnumerator.MoveNext.
An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying or deleting elements, the enumerator is irrecoverably invalidated and the next call to IEnumerator.MoveNext or IEnumerator.Reset throws an InvalidOperationException. If the collection is modified between IEnumerator.MoveNext and IEnumerator.Current, IEnumerator.Current will return the element that it is set to, even if the enumerator is already invalidated.
The enumerator does not have exclusive access to the collection; therefore, enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads could still modify the collection, which causes the enumerator to throw an exception. 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.
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
array
index
Exception Type | Condition |
---|---|
ArgumentNullException | array is null. |
ArgumentOutOfRangeException | index is less than zero. |
ArgumentException | array is multidimensional. -or- index is equal to or greater than the length of array. -or- The number of elements in the source NameObjectCollectionBase.KeysCollection is greater than the available space from index to the end of the destination array. |
InvalidCastException | The type of the source NameObjectCollectionBase.KeysCollection cannot be cast automatically to the type of the destination array. |
This method uses Array.Copy to copy the elements.
public virtual string ToString(); |