NameValueCollection.Add 方法

定义

将项添加到当前 NameValueCollectionAdds entries to the current NameValueCollection.

重载

Add(NameValueCollection)

将指定 NameValueCollection 中的项复制到当前 NameValueCollectionCopies the entries in the specified NameValueCollection to the current NameValueCollection.

Add(String, String)

将具有指定名称和值的项添加到 NameValueCollectionAdds an entry with the specified name and value to the NameValueCollection.

Add(NameValueCollection)

将指定 NameValueCollection 中的项复制到当前 NameValueCollectionCopies the entries in the specified NameValueCollection to the current NameValueCollection.

public:
 void Add(System::Collections::Specialized::NameValueCollection ^ c);
public void Add (System.Collections.Specialized.NameValueCollection c);
member this.Add : System.Collections.Specialized.NameValueCollection -> unit
Public Sub Add (c As NameValueCollection)

参数

c
NameValueCollection

要复制到当前 NameValueCollection 中的 NameValueCollectionThe NameValueCollection to copy to the current NameValueCollection.

例外

该集合是只读的。The collection is read-only.

cnullc is null.

注解

如果 c 目标实例中已存在一个键 NameValueCollection ,则中的关联值 c 将添加到现有的以逗号分隔的值列表,这些值与目标实例中的同一键关联 NameValueCollectionIf 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.

如果 Count 已等于容量,则会 NameValueCollection 自动重新分配内部数组,并将现有元素复制到新数组,然后再添加新的元素。If Count already equals the capacity, the capacity of the NameValueCollection is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.

如果 Count 小于容量,则此方法是 O (1) 操作。If Count is less than the capacity, this method is an O(1) operation. 如果需要增加容量以容纳新元素,则此方法将成为) 操作的 O (n ,其中, nCountIf the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

另请参阅

适用于

Add(String, String)

将具有指定名称和值的项添加到 NameValueCollectionAdds an entry with the specified name and value to the NameValueCollection.

public:
 virtual void Add(System::String ^ name, System::String ^ value);
public virtual void Add (string name, string value);
public virtual void Add (string? name, string? value);
abstract member Add : string * string -> unit
override this.Add : string * string -> unit
Public Overridable Sub Add (name As String, value As String)

参数

name
String

要添加的项的 String 键。The String key of the entry to add. 键可以是 nullThe key can be null.

value
String

要添加的项的 String 值。The String value of the entry to add. 该值可以为 nullThe value can be null.

例外

该集合是只读的。The collection is read-only.

注解

如果目标实例中已存在指定的键 NameValueCollection ,则将指定的值添加到窗体中现有的以逗号分隔的值列表中 "value1,value2,value3"If the specified key already exists in the target NameValueCollection instance, the specified value is added to the existing comma-separated list of values in the form "value1,value2,value3". 值与目标实例中的相同键关联 NameValueCollectionThe values are associated with the same key in the target NameValueCollection instance.

如果 Count 已等于容量,则会 NameValueCollection 自动重新分配内部数组,并将现有元素复制到新数组,然后再添加新的元素。If Count already equals the capacity, the capacity of the NameValueCollection is increased by automatically reallocating the internal array, and the existing elements are copied to the new array before the new element is added.

如果 Count 小于容量,则此方法是 O (1) 操作。If Count is less than the capacity, this method is an O(1) operation. 如果需要增加容量以容纳新元素,则此方法将成为) 操作的 O (n ,其中, nCountIf the capacity needs to be increased to accommodate the new element, this method becomes an O(n) operation, where n is Count.

适用于