System.Collections.Specialized.NameValueCollection.Item Property
Gets or sets the value in the current instance that is associated with the specified key.

Syntax

This is the default property for this class.

public string this [string name] { get; set; }

Parameters

name
A string containing the key of the entry to locate.

Value

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 returns null, and attempting to set it creates a new entry using name .

Exceptions

TypeReason
ArgumentOutOfRangeException index is outside the valid range of indexes for the collection.
NotSupportedExceptionThe property is being set and the current instance is read-only.

Remarks

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 NameValueCollection.Add(NameValueCollection) method.

Requirements

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