NameValueCollection.Item[] 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定指定的 元素。NameValueCollection
多載
| 名稱 | Description |
|---|---|
| Item[Int32] |
取得 的項目位於指定索引。NameValueCollection |
| Item[String] |
取得或設定 中指定鍵 NameValueCollection的條目。 |
Item[Int32]
取得 的項目位於指定索引。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 A 包含集合指定索引處逗號分隔的值列表。
例外狀況
index 超出該集合有效索引範圍。
備註
此特性可透過以下語法存取集合中的特定元素: myCollection[index]。
此屬性無法被設定。 若要設定在指定索引的值,請使用 Item[GetKey(index)]。
C# 語言使用 this 關鍵字來定義索引器,而非實作該 Item[] 屬性。 Visual Basic 將 Item[] 實作為 default 屬性,提供相同的索引功能。
在指定索引處取得值是 O(n) 操作,其中 n 是值數。
另請參閱
適用於
Item[String]
取得或設定 中指定鍵 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
參數
屬性值
String A 包含與指定鍵相關聯的逗號分隔值列表(若找到);否則,為 null。
例外狀況
該集合是唯讀的,操作嘗試修改集合。
備註
此特性可透過以下語法存取集合中的特定元素: myCollection[name]。
如果指定的鍵已經存在於集合中,設定此屬性會覆蓋現有的值清單。 若要將新值附加到現有的值清單中,請使用該 Add 方法。
如果指定的鍵不存在於集合中,設定此屬性即可使用指定的鍵和指定值建立新條目。
注意事項
此屬性在以下情況下會回傳 null :1) 若未找到指定的金鑰;2) 若找到指定的鍵且其對應值為 null。 此性質不區分這兩種情況。
C# 語言使用 this 關鍵字來定義索引器,而非實作該 Item[] 屬性。 Visual Basic 將 Item[] 實作為 default 屬性,提供相同的索引功能。
取得或設定與指定鍵相關的值是 O(n) 操作,其中 n 是數值。