PropertyDescriptorCollection.Count PropertyDescriptorCollection.Count PropertyDescriptorCollection.Count PropertyDescriptorCollection.Count Property

定義

取得這個集合中屬性描述項的數目。Gets the number of property descriptors in the collection.

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

屬性值

這個集合中屬性描述項的數目。The number of property descriptors in the collection.

實作

範例

下列程式碼範例會使用Count屬性上列印的屬性數目button1The following code example uses the Count property to print the number of properties on button1. 它需要button1textBox1具現化表單上。It requires that button1 and textBox1 have been instantiated on a form.

private:
   void GetCount()
   {
      // Creates a new collection and assign it the properties for button1.
      PropertyDescriptorCollection^ properties = TypeDescriptor::GetProperties( button1 );
      
      // Prints the number of properties on button1 in a textbox.
      textBox1->Text = properties->Count.ToString();
   }
private void GetCount() {
    // Creates a new collection and assign it the properties for button1.
    PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(button1);
 
    // Prints the number of properties on button1 in a textbox.
    textBox1.Text = properties.Count.ToString();
 }

Private Sub GetCount()
    ' Creates a new collection and assign it the properties for button1.
    Dim properties As PropertyDescriptorCollection = TypeDescriptor.GetProperties(button1)
       
    ' Prints the number of properties on button1 in a textbox.
    textBox1.Text = properties.Count.ToString()
End Sub

備註

您可以使用Count屬性來設定限制的迴圈,逐一查看物件的集合。You can use the Count property to set the limits of a loop that iterates through a collection of objects. 由於集合是以零為起始的因此請務必使用Count - 1做為迴圈的上限。Because the collection is zero-based, be sure to use Count - 1 as the upper boundary of the loop.

適用於

另請參閱