共用方式為


AttributeCollection.Count 屬性

定義

會取得屬性數量。

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

屬性值

屬性的數量。

實作

範例

以下程式碼範例使用 該 Count 屬性,將屬性 button1 數量列印在文字框中。 它假設 且 button1textBox1 已被創造在一個表單上。

private:
   void GetCount()
   {
      // Creates a new collection and assigns it the attributes for button1.
      AttributeCollection^ attributes;
      attributes = TypeDescriptor::GetAttributes( button1 );
      
      // Prints the number of items in the collection.
      textBox1->Text = attributes->Count.ToString();
   }
void GetCount()
{
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);

    // Prints the number of items in the collection.
    textBox1.Text = attributes.Count.ToString();
}
Private Sub GetCount
    ' Creates a new collection and assigns it the attributes for button 1.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)
    ' Prints the number of items in the collection.
    textBox1.Text = attributes.Count.ToString
End Sub

備註

你可以用這個 Count 屬性設定一個循環的極限,讓它遍歷一組物件。 若集合為零基,務必將 作為 Count - 1 迴圈的上界。

適用於

另請參閱