AttributeCollection.Count Egenskap

Definition

Hämtar antalet attribut.

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

Egenskapsvärde

Antalet attribut.

Implementeringar

Exempel

I följande kodexempel används Count egenskapen för att skriva ut antalet egenskaper button1 i en textruta. Det förutsätter att button1 och textBox1 har skapats i ett formulär.

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

Kommentarer

Du kan använda Count egenskapen för att ange gränserna för en loop som itererar genom en samling objekt. Om samlingen är nollbaserad ska du använda Count - 1 den som den övre gränsen för loopen.

Gäller för

Se även