System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Class

Assembly: System.dll
Namespace: System.Collections.Specialized
Summary
Represents a collection of the String keys of a collection.
C# Syntax:
[Serializable]
public class NameObjectCollectionBase.KeysCollection : ICollection, IEnumerable
Thread Safety
Public static (non-instance) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

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.

See also:
System.Collections.Specialized Namespace

System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Member List:

Public Properties
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.
Public Methods
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.
Protected Methods
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.
Explicit Interface Implementations 
ICollection.CopyTo Copies the entire NameObjectCollectionBase.KeysCollection to a compatible one-dimensional Array, starting at the specified index of the target array.

Hierarchy:


System.Collections.Specialized.NameObjectCollectionBase.KeysCollection Member Details

Property: Count (read-only)
Summary
Gets the number of keys in the NameObjectCollectionBase.KeysCollection.
C# Syntax:
public int Count {get;}
Implements:
ICollection.Count

Return to top


Property: Item (read-only)
Summary
Gets the entry at the specified index of the collection.
C# Syntax:
public string this[int index] {get;}
Parameters:

index

The zero-based index of the entry to locate in the collection. The zero-based index of the entry to locate in the collection.

Exceptions
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.
Remarks
This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[index] (In Visual Basic, myCollection(index) ).

Return to top


Method: Equals(
   object obj
)
Inherited
See base class member description: System.Object.Equals
C# Syntax:
public virtual bool Equals(
   object obj
);

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Finalize()
Inherited
See base class member description: System.Object.Finalize
C# Syntax:
~KeysCollection();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: Get(
   int index
)
Summary
Gets the key at the specified index of the collection.
C# Syntax:
public virtual string Get(
   int index
);
Parameters:

index

The zero-based index of the key to get from the collection. The zero-based index of the key to get from the collection.

Return Value:
A String that contains the key at the specified index of the collection.
Exceptions
Exception Type Condition
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.

Return to top


Method: GetEnumerator()
Summary
Returns an enumerator that can iterate through the NameObjectCollectionBase.KeysCollection.
C# Syntax:
public IEnumerator GetEnumerator();
Return Value:
An IEnumerator for the NameObjectCollectionBase.KeysCollection.
Implements:
IEnumerable.GetEnumerator
Remarks
This enumerator returns the keys of the collection as strings.

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.

Return to top


Method: GetHashCode()
Inherited
See base class member description: System.Object.GetHashCode
C# Syntax:
public virtual int GetHashCode();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: GetType()
Inherited
See base class member description: System.Object.GetType
C# Syntax:
public Type GetType();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: MemberwiseClone()
Inherited
See base class member description: System.Object.MemberwiseClone
C# Syntax:
protected object MemberwiseClone();

For more information on members inherited from System.Object click on the link above.

Return to top


Method: ICollection.CopyTo(
   Array array,
   int index
)
Summary
Copies the entire NameObjectCollectionBase.KeysCollection to a compatible one-dimensional Array, starting at the specified index of the target array.
C# Syntax:
void ICollection.CopyTo(
   Array array,
   int index
);
Parameters:

array

The one-dimensional Array that is the destination of the elements copied from NameObjectCollectionBase.KeysCollection. The Array must have zero-based indexing.

index

The zero-based index in array at which copying begins.

Exceptions
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.
Implements:
ICollection.CopyTo
Remarks
The specified array must be of a compatible type.

This method uses Array.Copy to copy the elements.

Return to top


Method: ToString()
Inherited
See base class member description: System.Object.ToString
C# Syntax:
public virtual string ToString();

For more information on members inherited from System.Object click on the link above.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.