[Serializable] |
This implementation does not provide a synchronized (thread-safe) wrapper for a NameValueCollection, but derived classes can create their own synchronized versions of the NameValueCollection using the NameObjectCollectionBase.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.
This class can be used for headers, query strings and form data.
The capacity is the number of key-and-value pairs that the NameValueCollection can contain. The default initial capacity is zero. The capacity is automatically increased as required.
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the NameValueCollection class that is empty, has the default initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer. |
ctor #2 | Overloaded:.ctor(int capacity) Initializes a new instance of the NameValueCollection class that is empty, has the specified initial capacity and uses the default case-insensitive hash code provider and the default case-insensitive comparer. |
ctor #3 | Overloaded:.ctor(NameValueCollection col) Copies the entries from the specified NameValueCollection to a new NameValueCollection with the same initial capacity as the number of entries copied and using the same hash code provider and the same comparer as the source collection. |
ctor #4 | Overloaded:.ctor(IHashCodeProvider hashProvider, IComparer comparer) Initializes a new instance of the NameValueCollection class that is empty, has the default initial capacity and uses the specified hash code provider and the specified comparer. |
ctor #5 | Overloaded:.ctor(int capacity, NameValueCollection col) Copies the entries from the specified NameValueCollection to a new NameValueCollection with the specified initial capacity or the same initial capacity as the number of entries copied, whichever is greater, and using the default case-insensitive hash code provider and the default case-insensitive comparer. |
ctor #7 | Overloaded:.ctor(int capacity, IHashCodeProvider hashProvider, IComparer comparer) Initializes a new instance of the NameValueCollection class that is empty, has the specified initial capacity and uses the specified hash code provider and the specified comparer. |
AllKeys | Read-only Gets all the keys in the NameValueCollection. |
Count (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Read-only See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Count Gets the number of key-and-value pairs contained in the NameObjectCollectionBase instance. |
Item | Read-only Overloaded: Item[int index] {get Gets the entry at the specified index of the NameValueCollection. |
Item | Read-write Overloaded: Item[string name] {get Gets or sets the entry with the specified key in the NameValueCollection. |
Keys (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Read-only See base class member description: System.Collections.Specialized.NameObjectCollectionBase.Keys Gets a NameObjectCollectionBase.KeysCollection instance that contains all the keys in the NameObjectCollectionBase instance. |
Add | Overloaded:Add(NameValueCollection c) Copies the entries in the specified NameValueCollection to the current NameValueCollection. |
Add | Overloaded:Add(string name, string value) Adds an entry with the specified name and value to the NameValueCollection. |
Clear | Invalidates the cached arrays and removes all entries from the NameValueCollection. |
CopyTo | Copies the entire NameValueCollection to a compatible one-dimensional Array, starting at the specified index of the target array. |
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 | Overloaded:Get(int index) Gets the values at the specified index of the NameValueCollection combined into one comma-separated list. |
Get | Overloaded:Get(string name) Gets the values associated with the specified key from the NameValueCollection combined into one comma-separated list. |
GetEnumerator (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetEnumerator Returns an enumerator that can iterate through the NameObjectCollectionBase. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetKey | Gets the key at the specified index of the NameValueCollection. |
GetObjectData (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.GetObjectData Implements the ISerializable interface and returns the data needed to serialize the NameObjectCollectionBase instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
GetValues | Overloaded:GetValues(int index) Gets the values at the specified index of the NameValueCollection. |
GetValues | Overloaded:GetValues(string name) Gets the values associated with the specified key from the NameValueCollection. |
HasKeys | Gets a value indicating whether the NameValueCollection contains keys that are not null. |
OnDeserialization (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.OnDeserialization Implements the ISerializable interface and raises the deserialization event when the deserialization is complete. |
Remove | Removes the entries with the specified key from the NameObjectCollectionBase instance. |
Set | Sets the value of an entry in the NameValueCollection. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #6 | Overloaded:.ctor(SerializationInfo info, StreamingContext context) Initializes a new instance of the NameValueCollection class that is serializable and uses the specified SerializationInfo and StreamingContext. |
IsReadOnly (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Read-write See base class member description: System.Collections.Specialized.NameObjectCollectionBase.IsReadOnly Gets or sets a value indicating whether the NameObjectCollectionBase instance is read-only. |
BaseAdd (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseAdd Adds an entry with the specified key and value into the NameObjectCollectionBase instance. |
BaseClear (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseClear Removes all entries from the NameObjectCollectionBase instance. |
BaseGet (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseGet(int index) See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetGets the value of the entry at the specified index of the NameObjectCollectionBase instance. |
BaseGet (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseGet(string name) See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetGets the value of the first entry with the specified key from the NameObjectCollectionBase instance. |
BaseGetAllKeys (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllKeys Returns a String array that contains all the keys in the NameObjectCollectionBase instance. |
BaseGetAllValues (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseGetAllValues() See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValuesReturns an Object array that contains all the values in the NameObjectCollectionBase instance. |
BaseGetAllValues (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseGetAllValues(Type type) See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetAllValuesReturns an array of the specified type that contains all the values in the NameObjectCollectionBase instance. |
BaseGetKey (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseGetKey Gets the key of the entry at the specified index of the NameObjectCollectionBase instance. |
BaseHasKeys (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseHasKeys Gets a value indicating whether the NameObjectCollectionBase instance contains entries whose keys are not null. |
BaseRemove (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemove Removes the entries with the specified key from the NameObjectCollectionBase instance. |
BaseRemoveAt (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseRemoveAt Removes the entry at the specified index of the NameObjectCollectionBase instance. |
BaseSet (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseSet(int index, object value) See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSetSets the value of the entry at the specified index of the NameObjectCollectionBase instance. |
BaseSet (inherited from System.Collections.Specialized.NameObjectCollectionBase) |
Overloaded:BaseSet(string name, object value) See base class member description: System.Collections.Specialized.NameObjectCollectionBase.BaseSetSets 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. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
InvalidateCachedArrays | Resets the cached arrays of the collection to null. |
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 NameValueCollection(); |
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
public NameValueCollection( |
capacity
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. |
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
public NameValueCollection(NameValueCollection( |
col
Exception Type | Condition |
---|---|
ArgumentNullException | col is null. |
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
The elements of the new NameValueCollection are sorted in the same order as the source NameValueCollection.
public NameValueCollection( |
hashProvider
comparer
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
public NameValueCollection(int capacity, NameValueCollection( |
capacity
col
Exception Type | Condition |
---|---|
ArgumentNullException | col is null. |
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
protected NameValueCollection( |
info
context
public NameValueCollection( |
capacity
hashProvider
comparer
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | capacity is less than zero. |
The hash code provider dispenses hash codes for keys in the NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.
The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.
public virtual string[] AllKeys {get;}
|
The arrays returned by NameValueCollection.AllKeys are cached for better performance and are automatically refreshed when the collection changes. A derived class can invalidate the cached version by calling NameValueCollection.InvalidateCachedArrays, thereby forcing the arrays to be recreated.
public virtual int Count {get;}
|
protected bool IsReadOnly {get; set;}
|
public string this[int index] {get;}
|
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
myCollection[index]
. This property cannot be set. To set the value at a specified index, use
Item[GetKey(index)]
.
public string this[string name] {get; set;}
|
name
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[name]
.If the specified key already exists in the collection, setting this property overwrites the existing values with the specified value. To add the new value to the existing list of values, use the NameValueCollection.Add method.
If the specified key does not exist in the collection, setting this property creates a new entry using the specified key and the specified value.
public virtual NameObjectCollectionBase.KeysCollection Keys {get;}
|
public void Add( |
c
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
ArgumentNullException | col is null. |
name
value
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
If the same value already exists under the same key in the collection, the new value overwrites the old value.
name
value
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
protected void BaseClear(); |
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
name
protected string[] BaseGetAllKeys(); |
protected object[] BaseGetAllValues(); |
type
Exception Type | Condition |
---|---|
ArgumentNullException | type is null. |
ArgumentException | type is not a valid Type. |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
protected bool BaseHasKeys(); |
protected void BaseRemove( |
name
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. -or- The collection has a fixed size. |
protected void BaseRemoveAt( |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
NotSupportedException | The collection is read-only. -or- The collection has a fixed size. |
index
value
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
name
value
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
public void Clear(); |
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
dest
index
Exception Type | Condition |
---|---|
ArgumentNullException | dest is null. |
ArgumentOutOfRangeException | index is less than zero. |
ArgumentException | dest is multidimensional. -or- index is equal to or greater than the length of dest. -or- The number of elements in the source NameValueCollection is greater than the available space from index to the end of the destination dest. |
InvalidCastException | The type of the source NameValueCollection cannot be cast automatically to the type of the destination dest. |
This method uses Array.Copy to copy the elements.
~NameValueCollection(); |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
name
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(); |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
public virtual void GetObjectData( |
info
context
Exception Type | Condition |
---|---|
ArgumentNullException | info is null. |
public Type GetType(); |
index
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | index is outside the valid range of indexes for the collection. |
name
public bool HasKeys(); |
protected void InvalidateCachedArrays(); |
protected object MemberwiseClone(); |
public virtual void OnDeserialization( |
sender
Exception Type | Condition |
---|---|
SerializationException | The SerializationInfo object associated with the current NameObjectCollectionBase instance is invalid. |
public virtual void Remove( |
name
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. -or- The collection has a fixed size. |
name
value
Exception Type | Condition |
---|---|
NotSupportedException | The collection is read-only. |
If the specified key does not exist in the collection, this method creates a new entry using the specified key and the specified value.
public virtual string ToString(); |