語言

StringCollection.Item[Int32] 屬性

定義

取得或設定位於指定索引處的專案。

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

參數

index
Int32

以零為基礎的索引,要取得或設定。

屬性值

位於指定索引的元素。

例外狀況

index 小於零。

-或-

index 等於或大於 Count

備註

此特性可透過以下語法存取集合中的特定元素: myCollection[index]

StringCollection 接受 null 為有效值,並允許重複元素。

C# 語言使用 this 關鍵字來定義索引器,而非實作該 Item[] 屬性。 Visual Basic 將 Item[] 實作為 default 屬性,提供相同的索引功能。

取得此屬性的值為 O(1) 運算;設定屬性也是 O(1) 操作。

適用於

另請參閱