System.Collections.Specialized.NameValueCollection Class

Represents a collection of associated string keys and string values that can be accessed either with the key or with the index.

See Also: NameValueCollection Members

Syntax

public class NameValueCollection : NameObjectCollectionBase

Remarks

This collection is based on the System.Collections.Specialized.NameObjectCollectionBase class. However, unlike the System.Collections.Specialized.NameObjectCollectionBase, this class stores multiple string values under a single key.

This class can be used for headers, query strings and form data.

Each element is a key/value pair.

Collections of this type do not preserve the ordering of element, and no particular ordering is guaranteed when enumerating the collection.

The capacity of a System.Collections.Specialized.NameValueCollection is the number of elements the System.Collections.Specialized.NameValueCollection can hold. As elements are added to a System.Collections.Specialized.NameValueCollection, the capacity is automatically increased as required through reallocation.

The hash code provider dispenses hash codes for keys in the System.Collections.Specialized.NameValueCollection. The default hash code provider is the CaseInsensitiveHashCodeProvider.

The comparer determines whether two keys are equal. The default comparer is the CaseInsensitiveComparer.

In .NET Framework version 1.0, this class uses culture-sensitive string comparisons. However, in .NET Framework version 1.1 and later, this class uses System.Globalization.CultureInfo.InvariantCulture when comparing strings. For more information about how culture affects comparisons and sorting, see Comparing and Sorting Data for a Specific Culture and Performing Culture-Insensitive String Operations.

null is allowed as a key or as a value.

Note:

The NameValueCollection.Get(string) method does not distinguish between null which is returned because the specified key is not found and null which is returned because the value associated with the key is null.

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Requirements

Namespace: System.Collections.Specialized
Assembly: System (in System.dll)
Assembly Versions: 1.0.x.x, 1.0.5000.0, 2.0.0.0, 4.0.0.0