public class StringDictionary : IEnumerable
|
This implementation does not provide a synchronized (thread-safe) wrapper for a StringDictionary, but derived classes can create their own synchronized versions of the StringDictionary using the StringDictionary.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.
ctor #1 | Default constructor. This constructor is called by derived class constructors to initialize state in this type. Initializes a new instance of the StringDictionary class. |
Count | Read-only Gets the number of key-and-value pairs in the StringDictionary. |
IsSynchronized | Read-only Gets a value that indicates whether access to the StringDictionary is synchronized (thread-safe). |
Item | Read-write Gets or sets the value associated with the specified key. |
Keys | Read-only Gets a collection of keys in the StringDictionary. |
SyncRoot | Read-only Gets an object that can be used to synchronize access to the StringDictionary. |
Values | Read-only Gets a collection of values in the StringDictionary. |
Add | Adds an entry with the specified key and value into the StringDictionary. |
Clear | Removes all entries from the StringDictionary. |
ContainsKey | Determines if the StringDictionary contains a specific key. |
ContainsValue | Determines if the StringDictionary contains a specific value. |
CopyTo | Copies the string dictionary values to a one-dimensional Array instance at the specified index. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetEnumerator | Returns an enumerator that can iterate through the string dictionary. |
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. |
Remove | Removes the entry with the specified key from the string dictionary. |
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. |
Hierarchy:
public StringDictionary(); |
public virtual int Count {get;}
|
public virtual bool IsSynchronized {get;}
|
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.
The following code example shows how to lock the collection using the StringDictionary.SyncRoot during the entire enumeration:
StringDictionary myCollection = new StringDictionary(); lock( myCollection.SyncRoot ) { foreach ( Object item in myCollection ) { // Insert your code here. } }
public virtual string this[string key] {get; set;}
|
key
public virtual ICollection Keys {get;}
|
Changes to the StringDictionary will continue to be reflected in the returned ICollection. It is not a static copy.
public virtual object SyncRoot {get;}
|
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.
The following code example shows how to lock the collection using the StringDictionary.SyncRoot during the entire enumeration:
StringDictionary myCollection = new StringDictionary(); lock( myCollection.SyncRoot ) { foreach ( Object item in myCollection ) { // Insert your code here. } }
public virtual ICollection Values {get;}
|
Changes to the StringDictionary will continue to be reflected in the returned ICollection. It is not a static copy.
key
value
Exception Type | Condition |
---|---|
ArgumentNullException | The key is null. |
ArgumentException | An entry with the same key already exists in the StringDictionary. |
NotSupportedException | The StringDictionary is read-only. |
public virtual void Clear(); |
Exception Type | Condition |
---|---|
NotSupportedException | The StringDictionary is read-only. |
key
Exception Type | Condition |
---|---|
ArgumentNullException | The key is null. |
The key is handled in a case-insensitive manner; it will be translated to lower case before it is used.
value
This method uses a linear search; therefore, the average execution time is proportional to the size of the StringDictionary. That is, this implementation is an O(n) operation.
array
index
Exception Type | Condition |
---|---|
ArgumentException | The array is multidimensional, or the number of elements in the Hashtable is greater than the available space between index and the end of array |
ArgumentNullException | The array is a null |
ArgumentOutOfRangeException | The index is less than the array's lower bound. |
The elements copied to the Array are sorted in the same order that the enumerator iterates through the StringDictionary.
~StringDictionary(); |
public virtual IEnumerator GetEnumerator(); |
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(); |
public virtual void Remove( |
key
Exception Type | Condition |
---|---|
ArgumentNullException | The key is null. |
NotSupportedException | The StringDictionary is read-only. |
public virtual string ToString(); |