Szerkesztés

Megosztás a következőn keresztül:


NameValueCollection.Item[] Property

Definition

Gets or sets the specified entry of the NameValueCollection.

Overloads

Item[Int32]

Gets the entry at the specified index of the NameValueCollection.

Item[String]

Gets or sets the entry with the specified key in the NameValueCollection.

Item[Int32]

Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs

Gets the entry at the specified index of the NameValueCollection.

public:
 property System::String ^ default[int] { System::String ^ get(int index); };
public string this[int index] { get; }
public string? this[int index] { get; }
member this.Item(int) : string
Default Public ReadOnly Property Item(index As Integer) As String

Parameters

index
Int32

The zero-based index of the entry to locate in the collection.

Property Value

A String that contains the comma-separated list of values at the specified index of the collection.

Exceptions

index is outside the valid range of indexes for the collection.

Remarks

This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[index].

This property cannot be set. To set the value at a specified index, use Item[GetKey(index)].

The C# language uses the this keyword to define the indexers instead of implementing the Item[] property. Visual Basic implements Item[] as a default property, which provides the same indexing functionality.

Retrieving the values at the specified index is an O(n) operation, where n is the number of values.

See also

Applies to

Item[String]

Source:
NameValueCollection.cs
Source:
NameValueCollection.cs
Source:
NameValueCollection.cs

Gets or sets the entry with the specified key in the NameValueCollection.

public:
 property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); void set(System::String ^ name, System::String ^ value); };
public string this[string name] { get; set; }
public string? this[string? name] { get; set; }
member this.Item(string) : string with get, set
Default Public Property Item(name As String) As String

Parameters

name
String

The String key of the entry to locate. The key can be null.

Property Value

A String that contains the comma-separated list of values associated with the specified key, if found; otherwise, null.

Exceptions

The collection is read-only and the operation attempts to modify the collection.

Remarks

This property provides the ability to access a specific element in the collection by using the following syntax: myCollection[name].

If the specified key already exists in the collection, setting this property 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, setting this property creates a new entry using the specified key and the specified value.

Caution

This property returns null in the following cases: 1) if the specified key is not found; and 2) if the specified key is found and its associated value is null. This property does not distinguish between the two cases.

The C# language uses the this keyword to define the indexers instead of implementing the Item[] property. Visual Basic implements Item[] as a default property, which provides the same indexing functionality.

Retrieving or setting the values associated with the specified key is an O(n) operation, where n is the number of values.

See also

Applies to