Collection.Count プロパティ

定義

コレクション内の要素の数を取得します。

public:
 property int Count { int get(); };
public int Count { get; }
member this.Count : int
Public ReadOnly Property Count As Integer

プロパティ値

コレクション内の要素の数。

実装

この例では、Count プロパティを使用して、変数 birthdaysCollection オブジェクト内の要素の数を表示します。

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")
MsgBox("Number of birthdays in collection: " & CStr(birthdays.Count))

Collection オブジェクトは 1 ベース、つまり、要素のインデックス値の範囲は 1 から Count プロパティの値までであることを意味します。

注釈

Count プロパティを使用して、Collection オブジェクト内の要素の数を調べます。

適用対象