AttributeCollection.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 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 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 作為迴圈的上限。

適用於

另請參閱