TableRowCollection.Count Property


获取集合当前包含的项数。Gets the number of items currently contained by the collection.

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

Property Value


集合当前包含的项数。The number of items currently contained by the collection.



Capacity 属性表示在此集合中存储项的预分配槽的数目,而 Count 属性表示集合中当前项的实际数目。The Capacity property represents the number of pre-allocated slots for storing items in this collection, whereas the Count property represents the actual number of items currently in the collection. Capacity 的值始终至少与 Count的值相同。The value of Capacity is always at least as large as the value of Count.

当新添加的集合项导致集合计数超出集合容量时,会自动增加容量以容纳新添加的集合项。When newly added collection items cause the collection count to exceed the collection capacity, the capacity is automatically increased to accommodate the newly added collection items. 增加收集容量需要分配额外的收集槽,这会产生性能和内存开销。Increasing the collection capacity involves allocating additional collection slots, which incurs both performance and memory overhead. 如果事先知道收集项的总数量或最大数量,请使用 Capacity 属性优化集合容量。Use the Capacity property to optimize the collection capacity in cases where the total or maximum number of collection items is known in advance. 使用 TrimToSize 方法可使集合容量与当前的集合计数成一。Use the TrimToSize method to cause the collection capacity to equalized with the current collection count.

Applies to

See also