PropertyDescriptorCollection.Count 屬性

定義

取得這個集合中屬性描述項的數目。

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

屬性值

這個集合中屬性描述項的數目。

實作

範例

下列程式代碼範例會 Count 使用 屬性來列印 上的 button1屬性數目。 它要求 button1 已在表單上具現化 和 textBox1

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 屬性來設定迴圈的限制,以逐一查看 物件的集合。 因為集合是以零起始,所以請務必使用 Count - 1 作為迴圈的上限。

適用於

另請參閱