This documentation is archived and is not being maintained.

NameValueCollection.Set Method

Sets the value of an entry in the NameValueCollection.

Namespace: System.Collections.Specialized
Assembly: System (in system.dll)

virtual void Set (
	String^ name, 
	String^ value
public void Set (
	String name, 
	String value
public function Set (
	name : String, 
	value : String
Not applicable.



The String key of the entry to add the new value to. The key can be a null reference (Nothing in Visual Basic).


The Object that represents the new value to add to the specified entry. The value can be a null reference (Nothing in Visual Basic).

Exception typeCondition


The collection is read-only.

If the specified key already exists in the collection, this method overwrites the existing list of values with the specified value. To append the new value to the existing list of values, use the Add method.

If the specified key does not exist in the collection, this method creates a new entry using the specified key and the specified value.

This method is an O(1) operation.

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0