NameValueCollection.Item[String] 屬性

定義

取得或設定 NameValueCollection 的指定項目。Gets or sets the specified entry of the NameValueCollection.

多載

Item[Int32]

取得 NameValueCollection 的指定索引的項目。Gets the entry at the specified index of the NameValueCollection.

Item[String]

使用 NameValueCollection 中指定的索引鍵來取得或設定項目。Gets or sets the entry with the specified key in the NameValueCollection.

Item[Int32]

取得 NameValueCollection 的指定索引的項目。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; }
member this.Item(int) : string
Default Public ReadOnly Property Item(index As Integer) As String

參數

index
Int32

集合中以零起始的項目索引。The zero-based index of the entry to locate in the collection.

屬性值

String,包含集合的指定索引值的逗號分隔清單。A String that contains the comma-separated list of values at the specified index of the collection.

例外狀況

index 超出集合索引的有效範圍。index is outside the valid range of indexes for the collection.

備註

這個屬性可以使用下列語法提供存取集合中特定元素的能力:myCollection[index]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. 若要在指定的索引處設定值, Item[GetKey(index)]請使用。To set the value at a specified index, use Item[GetKey(index)].

語言會使用 this 關鍵字來定義索引子,而不是執行Item[String]屬性。 C#The C# language uses the this keyword to define the indexers instead of implementing the Item[String] property. Visual Basic 實作為預設屬性,它會提供相同的索引功能。 Item[String]Visual Basic implements Item[String] as a default property, which provides the same indexing functionality.

抓取指定索引處的值是 O (n)運算,其中n是值的數目。Retrieving the values at the specified index is an O(n) operation, where n is the number of values.

另請參閱

Item[String]

使用 NameValueCollection 中指定的索引鍵來取得或設定項目。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; }
member this.Item(string) : string with get, set
Default Public Property Item(name As String) As String

參數

name
String

要找出的項目的 String 索引鍵。The String key of the entry to locate. 這個索引鍵可以是 nullThe key can be null.

屬性值

String,包含與指定索引鍵相關值的逗號分隔清單 (如果找到),否則為 nullA String that contains the comma-separated list of values associated with the specified key, if found; otherwise, null.

例外狀況

該集合是唯讀的,並且作業會嘗試修改集合。The collection is read-only and the operation attempts to modify the collection.

備註

這個屬性可以使用下列語法提供存取集合中特定元素的能力:myCollection[name]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. 若要將新值附加至現有的值清單,請使用Add方法。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.

警告

null在下列情況中,這個屬性會傳回:1)如果找不到指定的索引鍵,則為,如果找到指定的索引鍵,且其相關聯的值為null,則為2)。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.

語言會使用 this 關鍵字來定義索引子,而不是執行Item[String]屬性。 C#The C# language uses the this keyword to define the indexers instead of implementing the Item[String] property. Visual Basic 實作為預設屬性,它會提供相同的索引功能。 Item[String]Visual Basic implements Item[String] as a default property, which provides the same indexing functionality.

抓取或設定與指定索引鍵相關聯的值是 O (n)運算,其中n是值的數目。Retrieving or setting the values associated with the specified key is an O(n) operation, where n is the number of values.

另請參閱

適用於