Collection.Count 屬性

定義

取得集合中元素的數量。

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

屬性值

集合中的元素數量。

實作

範例

此範例說明了如何使用屬性Count顯示變數 birthdays中物件的Collection元素數量。

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 的值。

備註

利用該 Count 屬性來決定物件中 Collection 元素的數量。

適用於