Collection.Item[] プロパティ

定義

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

オーバーロード

名前 説明
Item[Int32]

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

Item[Object]

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

Item[String]

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

Item[Int32]

ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

public:
 property System::Object ^ default[int] { System::Object ^ get(int Index); };
public object? this[int Index] { get; }
public object this[int Index] { get; }
member this.Item(int) : obj
Default Public ReadOnly Property Item(Index As Integer) As Object

パラメーター

Index
Int32

コレクションの要素の位置を指定する数値式。 Index は、1 からコレクションの Count プロパティの値までの数値である必要があります。 または (B) コレクションの要素の位置またはキー文字列を指定する Object 式。

プロパティ値

位置またはキーによって Collection オブジェクトの特定の要素。

次の例では、 Item プロパティを使用して、コレクション内のオブジェクトへの参照を取得します。 birthdaysCollection オブジェクトとして作成し、キー "Bill"Index引数として使用して、Bill の誕生日を表すオブジェクトを取得します。

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Add(New DateTime(2001, 1, 14), "Mike")
birthdays.Add(New DateTime(2001, 1, 15), "Pete")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

最初の呼び出しでは Item プロパティが明示的に指定されますが、2 つ目の呼び出しでは明示的に指定されないことに注意してください。 Item プロパティがCollection オブジェクトの既定のプロパティであるため、どちらの呼び出しも機能します。

注釈

IndexObject型の場合、Item プロパティは、StringCharChar配列、または整数値として処理しようとします。 Item IndexStringまたはIntegerに変換できない場合は、ArgumentException例外がスローされます。

Item プロパティは、コレクションの既定のプロパティです。 したがって、次のコード行は同等です。

MsgBox(CStr(customers.Item(1)))
MsgBox(CStr(customers(1)))

適用対象

Item[Object]

ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

public:
 property System::Object ^ default[System::Object ^] { System::Object ^ get(System::Object ^ Index); };
public object? this[object Index] { get; }
public object this[object Index] { get; }
member this.Item(obj) : obj
Default Public ReadOnly Property Item(Index As Object) As Object

パラメーター

Index
Object

コレクションの要素の位置を指定する数値式。 Index は、1 からコレクションの Count プロパティの値までの数値である必要があります。 または (B) コレクションの要素の位置またはキー文字列を指定する Object 式。

プロパティ値

位置またはキーによって Collection オブジェクトの特定の要素。

次の例では、 Item プロパティを使用して、コレクション内のオブジェクトへの参照を取得します。 birthdaysCollection オブジェクトとして作成し、キー "Bill"Index引数として使用して、Bill の誕生日を表すオブジェクトを取得します。

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Add(New DateTime(2001, 1, 14), "Mike")
birthdays.Add(New DateTime(2001, 1, 15), "Pete")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

最初の呼び出しでは Item プロパティが明示的に指定されますが、2 つ目の呼び出しでは明示的に指定されないことに注意してください。 Item プロパティがCollection オブジェクトの既定のプロパティであるため、どちらの呼び出しも機能します。

注釈

IndexObject型の場合、Item プロパティは、StringCharChar配列、または整数値として処理しようとします。 Item IndexStringまたはIntegerに変換できない場合は、ArgumentException例外がスローされます。

Item プロパティは、コレクションの既定のプロパティです。 したがって、次のコード行は同等です。

MsgBox(CStr(customers.Item(1)))
MsgBox(CStr(customers(1)))

適用対象

Item[String]

ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb
ソース:
Collection.vb

位置またはキーによって、 Collection オブジェクトの特定の要素を取得します。

public:
 property System::Object ^ default[System::String ^] { System::Object ^ get(System::String ^ Key); };
public object? this[string Key] { get; }
public object this[string Key] { get; }
member this.Item(string) : obj
Default Public ReadOnly Property Item(Key As String) As Object

パラメーター

Key
String

位置指定インデックスではなく、コレクションの要素にアクセスするために使用できるキー文字列を指定する一意の String 式。 Key は、要素がコレクションに追加されたときに指定された Key 引数に対応する必要があります。

プロパティ値

位置またはキーによって Collection オブジェクトの特定の要素。

次の例では、 Item プロパティを使用して、コレクション内のオブジェクトへの参照を取得します。 birthdaysCollection オブジェクトとして作成し、キー "Bill"Index引数として使用して、Bill の誕生日を表すオブジェクトを取得します。

Dim birthdays As New Collection()
birthdays.Add(New DateTime(2001, 1, 12), "Bill")
birthdays.Add(New DateTime(2001, 1, 13), "Joe")
birthdays.Add(New DateTime(2001, 1, 14), "Mike")
birthdays.Add(New DateTime(2001, 1, 15), "Pete")
Dim aBirthday As DateTime
aBirthday = birthdays.Item("Bill")
MsgBox(CStr(aBirthday))
aBirthday = birthdays("Bill")
MsgBox(CStr(aBirthday))

最初の呼び出しでは Item プロパティが明示的に指定されますが、2 つ目の呼び出しでは明示的に指定されないことに注意してください。 Item プロパティがCollection オブジェクトの既定のプロパティであるため、どちらの呼び出しも機能します。

注釈

IndexObject型の場合、Item プロパティは、StringCharChar配列、または整数値として処理しようとします。 Item IndexStringまたはIntegerに変換できない場合は、ArgumentException例外がスローされます。

Item プロパティは、コレクションの既定のプロパティです。 したがって、次のコード行は同等です。

MsgBox(CStr(customers.Item(1)))
MsgBox(CStr(customers(1)))

適用対象