Collection.Count 屬性

定義

取得集合中的元素數目。Gets the number of elements in a collection.

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

屬性值

集合中的項目數目。The number of elements in a collection.

實作

範例

這個範例說明如何使用 Count 屬性,以在變數 birthdays中顯示 Collection 物件中的元素數目。This example illustrates the use of the Count property to display the number of elements in a Collection object in the variable birthdays.

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到 Count 屬性的值。The Collection object is one-based, which means that the index values of the elements range from 1 through the value of the Count property.

備註

使用 Count 屬性來判斷 Collection 物件中的元素數目。Use the Count property to determine the number of elements in a Collection object.

適用於