public class NameValueCollection: ICollection, IEnumerable
Object
NameValueCollectionThis type implements ICollection and IEnumerable.
System
Networking
Represents a collection of associated String keys and String values.
This class can be used for headers, query strings and form data. Each key in the collection is associated with one or more values. Multiple values for a particular key are contained in a single String .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 comparer determines whether two keys are equal.
DefaultMemberAttribute("Item")
System.Collections.Specialized Namespace
NameValueCollection Constructors
NameValueCollection(int, System.Collections.IHashCodeProvider, System.Collections.IComparer) Constructor
NameValueCollection(int, System.Collections.Specialized.NameValueCollection) Constructor
NameValueCollection(int) Constructor
NameValueCollection(System.Collections.IHashCodeProvider, System.Collections.IComparer) Constructor
NameValueCollection(System.Collections.Specialized.NameValueCollection) Constructor
NameValueCollection() Constructor
NameValueCollection Methods
NameValueCollection.Add(System.String, System.String) Method
NameValueCollection.Add(System.Collections.Specialized.NameValueCollection) Method
NameValueCollection.Clear Method
NameValueCollection.CopyTo Method
NameValueCollection.Get(System.String) Method
NameValueCollection.Get(int) Method
NameValueCollection.GetEnumerator Method
NameValueCollection.GetKey Method
NameValueCollection.GetValues(System.String) Method
NameValueCollection.GetValues(int) Method
NameValueCollection.HasKeys Method
NameValueCollection.InvalidateCachedArrays Method
NameValueCollection.Remove Method
NameValueCollection.Set Method
NameValueCollection Properties
NameValueCollection.AllKeys Property
NameValueCollection.Count Property
NameValueCollection.IsReadOnly Property
NameValueCollection.IsSynchronized Property
NameValueCollection.Item(System.String) Property
NameValueCollection.Item(int) Property
NameValueCollection.SyncRoot Property
public NameValueCollection(int capacity, IHashCodeProvider hashProvider, IComparer comparer);
Constructs and initializes new instance of the NameValueCollection class with the specified initial capacity, hash code provider, and comparer.
- capacity
- A Int32 containing the initial number of entries that the NameValueCollection can contain.
- hashProvider
- The IHashCodeProvider that will supply the hash codes for all keys in the new instance.
- comparer
- The IComparer to use to determine whether two keys in the new instance are equal.
Exception Type Condition ArgumentOutOfRangeException capacity < 0.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public NameValueCollection(int capacity, NameValueCollection col);
Constructs and initializes new instance of the NameValueCollection class that contains the same values as the specified NameValueCollection and either the specified capacity or the capacity of the specified collection, whichever is greater.
- capacity
- A Int32 containing the initial number of entries that the new instance can contain.
- col
- The NameValueCollection used to initialize the new instance.
Exception Type Condition ArgumentNullException col is null
.ArgumentOutOfRangeException capacity is < 0.
The new instance is initialized with the default IHashCodeProvider and IComparer .
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public NameValueCollection(int capacity);
Constructs and initializes a new instance of the NameValueCollection class with the specified initial capacity.
- capacity
- A Int32 containing the initial number of entries that the new instance can contain.
Exception Type Condition ArgumentOutOfRangeException capacity < 0.
The new instance is initialized with the default IHashCodeProvider and IComparer .
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public NameValueCollection(IHashCodeProvider hashProvider, IComparer comparer);
Constructs and initializes a new instance of the NameValueCollection class with the specified IHashCodeProvider and the specified IComparer .
- hashProvider
- The IHashCodeProvider that supplies the hash codes for all keys in the new instance; or,
null
to use the default hash code provider.
- comparer
- The IComparer to use to determine whether two keys are equal. Specify
null
to use the default comparer.
The new instance is initialized with the default capacity of zero.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public NameValueCollection(NameValueCollection col);
Constructs and initializes a new instance of the NameValueCollection class using the values of the specified NameValueCollection .
- col
- The NameValueCollection used to initialize the new instance.
Exception Type Condition ArgumentNullException col is null
.
The capacity, values, and order of values of the new instance are equal to the capacity and values of col . The IHashCodeProvider and IComparer of the new instance are the default instances.The elements of the new NameValueCollection are sorted in the same order as the source NameValueCollection.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public NameValueCollection();
Constructs and initializes a new instance of the NameValueCollection class.
The new instance is initialized with the default initial capacity, IHashCodeProvider, and IComparer.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual void Add(string name, string value);
Adds an entry with the specified key and value to the current instance.
- name
- A String that represents the key of the entry to add. Can be
null
.
- value
- A String that represents the value of the entry to add. Can be
null
.
Exception Type Condition NotSupportedException The current instance is read-only.
[Behaviors: As described above.]
[Default: If the specified key already exists in the current instance, the specified value is added to the existing comma-separated list of values associated with the same key.
Attempting to assign the same value to an existing key adds a new value to that key, thus providing two (or more) copies of the same value associated with the key.
]
[Overrides: Override this method to customize the default behavior in a type derived from the current type.]
[Usage: Use this method to add an entry to the current instance.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public void Add(NameValueCollection c);
Copies the entries from the specified NameValueCollection to the current instance.
- c
- The NameValueCollection to copy to the current instance.
Exception Type Condition NotSupportedException The current instance is read-only. ArgumentNullException c is null
.
If a key in c already exists in the target NameValueCollection instance, the associated value in c is added to the existing comma-separated list of values associated with the same key in the target NameValueCollection instance.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public void Clear();
Invalidates the cached arrays and removes all entries from the current instance.
Exception Type Condition NotSupportedException The current instance is read-only.
The value of each key and value in the current instance is set tonull
.If the current instance is empty, it remains unchanged and no exception is thrown.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public void CopyTo(Array dest, int index);
Copies the elements from the current instance to the specified Array, starting at the specified index in that array.
- dest
- A one-dimensional, zero-based Array that is the destination of the elements copied from the current instance.
- index
- A Int32 containing the zero-based index in dest at which copying begins.
Exception Type Condition ArgumentNullException dest is null
.ArgumentOutOfRangeException index < 0. ArgumentException dest has more than one dimension. -or-
index >= dest.Length.
-or-
The number of elements in the current instance is greater than the available space from index to the end of the destination dest.
InvalidCastException At least one element in the current instance is not assignment-compatible with the type of dest.
This method uses System.Array.Copy(System.Array,System.Array,System.Int32) to copy the elements.[Note: This method is implemented to support the ICollection interface.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string Get(string name);
Gets the values associated with the specified key from the current instance combined into one comma-separated list.
- name
- A String that specified the key of the entry that contains the values to get.
A String that contains a comma-separated list of the values associated with the specified key from the current instance, if found; otherwise,null
.
[Behaviors: As described above.]
[Default: If name is
null
, the values associated with the null key, if any, are returned; otherwise,null
is returned.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string Get(int index);
Returns the values at the specified index of the current instance.
- index
- A Int32 that specifies the zero-based index of the entry that contains the values to get from the current instance.
A String that contains a comma-separated list of the values at the specified index of the current instance, if found; otherwise,null
.
Exception Type Condition ArgumentOutOfRangeException index is outside the valid range of indices for the current instance.
[Behaviors: As described above.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual IEnumerator GetEnumerator()
Returns a IEnumerator for the current instance.
A IEnumerator for the current instance.
If the current instance is modified while an enumeration is in progress, a call to System.Collections.IEnumerator.MoveNext or System.Collections.IEnumerator.Reset throws InvalidOperationException.[Note: For detailed information regarding the use of an enumerator, see IEnumerator. This property is implemented to support the IEnumerable interface.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string GetKey(int index);
Returns the key at the specified index of the current instance.
- index
- A Int32 that specifies the zero-based index of the key to get from the current instance.
A String that contains the key at the specified index of the current instance, if found; otherwise,null
.
Exception Type Condition ArgumentOutOfRangeException index is outside the valid range of indices for the current instance.
[Behaviors: As described above.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string[] GetValues(string name);
Gets the values associated with the specified key from the current instance.
- name
- A String that specifies the key of the entry that contains the values to get.
A String array containing the values associated with name from the current instance, if found; otherwise,null
.
[Behaviors: As described above.]
[Default: If name is
null
, no exception is thrown andnull
is returned.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string[] GetValues(int index);
Returns an array that contains the values at the specified index of the current instance.
- index
- A Int32 that specifies the zero-based index of the entry that contains the values to get from the current instance.
A String array containing the values at the specified index of the current instance, if found; otherwise,null
.
Exception Type Condition ArgumentOutOfRangeException index is outside the valid range of indices for the current instance.
[Behaviors: As described above.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public bool HasKeys();
Gets a Boolean value indicating whether the current instance contains keys that are notnull
.
true
if the current instance contains keys that are notnull
; otherwise,false
.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
protected void InvalidateCachedArrays();
Resets the cached arrays of the current instance tonull
.
[Note: The array returned by System.Collections.Specialized.NameValueCollection.AllKeys is cached for better performance and is automatically refreshed when the collection changes. A derived class can invalidate the cached version by calling System.Collections.Specialized.NameValueCollection.InvalidateCachedArrays, thereby forcing the arrays to be recreated.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual void Remove(string name);
Removes the entry with the specified key from the current instance.
- name
- A String containing the key of the entry to remove from the current instance.
Exception Type Condition NotSupportedException The current instance is read-only.
[Behaviors: If name is found, the key name and its associated value are set tonull
. Removing an element does not alter the capacity of a NameValueCollection . ]
[Default: This method uses the System.Object.Equals(System.Object) implementation of name to locate name in the current instance. If name is not found in the current instance or is
null
, no exception is thrown and the current instance is unchanged. ]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual void Set(string name, string value);
Sets the value of the specified entry in the current instance to the specified value.
- name
- A String containing the key of the entry to add the new value to.
- value
- A String containing the new value to add to the specified entry.
Exception Type Condition NotSupportedException The current instance is read-only.
[Behaviors: If the specified key already exists in the current instance, this method overwrites the existing values with the specified value. (If the existing value contains a string of multiple comma-delimited values, the complete string is replaced with a single instance of value.) If the specified key does not exist in the current instance, this method creates a new entry using the specified key and the specified value.]
[Usage: Use the System.Collections.Specialized.NameValueCollection.Add(System.Collections.Specialized.NameValueCollection) method to add the new value to the existing list of values.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual string[] AllKeys { get; }
Gets all the keys in the current instance.
A String array containing all the keys of the current instance. If the current instance is empty, the value of this property is an empty array.
[Behaviors: This property is read-only.]
[Usage: The array returned by System.Collections.Specialized.NameValueCollection.AllKeys is cached for better performance and is automatically refreshed when the collection changes. A derived class can invalidate the cached version by calling System.Collections.Specialized.NameValueCollection.InvalidateCachedArrays, thereby forcing the array to be refreshed.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public virtual int Count { get; }
Gets the number of elements contained in the current instance.
A Int32 that indicates the number of elements contained in the current instance.
This property is read-only.[Note: This property is implemented to support the ICollection interface.
]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
protected bool IsReadOnly { get; set; }
Gets or sets a value indicating whether the current instance is read-only.
true
if the current instance is read-only; otherwise,false
.
This property is read-write.
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
bool ICollection.IsSynchronized { get; }
Implemented to support ICollection.[Note: For more information, see System.Collections.ICollection.IsSynchronized.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public string this[string name] { get; set; }
Gets or sets the value in the current instance that is associated with the specified key.
- name
- A String containing the key of the entry to locate.
A String that contains the comma-separated list of values associated with the specified key. If name is not contained in the current instance, attempting to get it returnsnull
, and attempting to set it creates a new entry using name .
Exception Type Condition NotSupportedException The property is being set and the current instance is read-only.
If the specified key already exists in the collection, setting this property overwrites the existing values with the specified value. (If the existing value contains a string of multiple comma-delimited values, the complete string is replaced with a single instance of the specified value.) 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.[Note: This property provides the ability to access a specific element in the current instance using the following notation: myCollection[key] .
To add the new value to the existing list of values, use the System.Collections.Specialized.NameValueCollection.Add(System.Collections.Specialized.NameValueCollection) method.
]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
public string this[int index] { get; }
Gets the value in the current instance that is associated with the specified index.
- index
- A Int32 that specifies the zero-based index of the entry to locate in the current instance.
A String that contains the comma-separated list of values at the specified index of the current instance.
Exception Type Condition ArgumentOutOfRangeException index is outside the valid range of indices for the current instance. NotSupportedException The property is being set and the current instance is read-only.
This property is read-only.[Note: This property provides the ability to access a specific element in the collection by using the following syntax:
myCollection[index]
.This property cannot be set. To set the value at a specified index, use
Item[GetKey(index)]
.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace
object ICollection.SyncRoot { get; }
Implemented to support ICollection.[Note: For more information, see System.Collections.ICollection.SyncRoot.]
System.Collections.Specialized.NameValueCollection Class, System.Collections.Specialized Namespace