NameValueCollection.Item[] 屬性

定義

取得或設定 NameValueCollection 的指定項目。

多載

Item[Int32]

取得 NameValueCollection 之指定索引處的項目。

Item[String]

取得或設定具有 NameValueCollection 中指定索引鍵的項目。

Item[Int32]

來源:
NameValueCollection.cs
來源:
NameValueCollection.cs
來源:
NameValueCollection.cs

取得 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

參數

index
Int32

集合中以零為基底的項目索引。

屬性值

String,包含集合指定索引處之值的逗號分隔清單。

例外狀況

index 超出集合索引的有效範圍。

備註

這個屬性可透過下列語法存取集合中的特定元素:myCollection[index]

無法設定這個屬性。 若指定的索引設定值, 請使用 Item[GetKey(index)]

C# 語言會使用此 關鍵詞來定義索引器,而不是實作 Item[] 屬性。 Visual Basic 會實作為Item[]預設屬性,以提供相同的索引功能。

擷取指定索引的值是 O (n) 作業,其中 n 是值數目。

另請參閱

適用於

Item[String]

來源:
NameValueCollection.cs
來源:
NameValueCollection.cs
來源:
NameValueCollection.cs

取得或設定具有 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

參數

name
String

要找出的項目的 String 索引鍵。 這個索引鍵可以是 null

屬性值

String,包含與指定索引鍵相關聯之值的逗號分隔清單 (如果找到的話),否則為 null

例外狀況

該集合是唯讀的,並且作業會嘗試修改集合。

備註

這個屬性可透過下列語法存取集合中的特定元素:myCollection[name]

如果集合中已有指定的索引鍵,則設定此屬性會覆寫具有指定值的現有值清單。 若要將新值附加至現有的值清單,請使用 Add 方法。

如果集合中不存在指定的索引鍵,則設定此屬性會使用指定的索引鍵和指定的值來建立新的專案。

警告

此屬性會在下列情況下傳回:如果找不到指定的索引鍵,則傳回 1) ;如果找到指定的索引鍵,則傳回 null 2) ,且其相關聯的值為 null。 這個屬性不會區分這兩種情況。

C# 語言會使用此 關鍵詞來定義索引器,而不是實作 Item[] 屬性。 Visual Basic 會實作為Item[]預設屬性,以提供相同的索引功能。

擷取或設定與指定索引鍵相關聯的值是 O (n) 作業,其中 n 是值數目。

另請參閱

適用於