共用方式為


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();
   }
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 迴路的上界。

適用於

另請參閱