NameValueCollection Class
Defined in: System.Collections.Specialized
Assembly: System.dll
Assembly: System.dll
Summary
Represents a collection of associated keys and values that, because the keys are not stored in a sorted order, can be accessed by index.
The keys and values can be any type of string.
A NameValueCollection object is essentially a dictionary, but it allows duplicate keys and does not sort the keys.
Syntax
public class NameValueCollection : ICloneable,
ICollection,
IEnumerable,
INameValueCollection
Inheritance
System.Object
↳ System.Collections.Specialized.NameValueCollection
Constructors
| Constructor | Description |
|---|---|
| NameValueCollection() | Initializes a new instance of the NameValueCollection class that is empty, has the default initial capacity, and uses the case-insensitive comparison. |
| NameValueCollection(IEqualityComparer) | Initializes a new instance of the NameValueCollection class that is empty, has the default initial capacity, and uses the specified IEqualityComparer. |
| NameValueCollection(Int32) | Initializes a new instance of the NameValueCollection class that is empty, has the specified initial capacity, and uses the case-insensitive comparison. |
| NameValueCollection(Int32, IEqualityComparer) | Initializes a new instance of the NameValueCollection class that is empty, has the specified initial capacity, and uses the specified IEqualityComparer. |
| NameValueCollection(NameValueCollection) | Initializes a new instance of the NameValueCollection class that contains elements copied from the specified NameValueCollection, uses the case-insensitive comparison, and has sufficient capacity to accommodate the number of elements copied. |
Properties
| Property | Description |
|---|---|
| AllKeys | Gets all the keys that are contained in the NameValueCollection. |
| Count | Gets the number of key/value pairs contained in the NameValueCollection. |
| Item(String) | Gets or sets the value associated with the specified key. If the specified key is not found, attempting to get it returns null, and attempting to set it adds a new element with the specified key and value. |
| Keys | Gets an ICollection that contains the keys in the NameValueCollection. |
Methods
| Method | Description |
|---|---|
| Add(String, String) | Adds an entry with the specified key and value to the NameValueCollection. |
| Add(String, String[]) | Adds an entry with the specified key and array of values to the NameValueCollection. |
| Clear() | Removes all entries from the NameValueCollection. |
| Clone() | Creates a shallow copy of the NameValueCollection. |
| Get(String) | Gets the value of the first entry with the specified key from the NameValueCollection. |
| GetAllKeys() | Gets all the keys that are contained in the NameValueCollection. |
| GetKey(Int32) | Gets the key of the entry at the specified index in the NameValueCollection. |
| GetValues(String) | Gets all the values associated with the specified key from the NameValueCollection. |
| Remove(String) | Removes all entries with the specified key from the NameValueCollection. |
| Set(String, String) | Sets the value of the first entry with the specified key to the specified value. If the specified key is not found, a new entry is added with the specified key and value. |
Remarks
Thread safety
Public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Namespace
System.Collections.Specialized
Assembly
System.dll