PropertyDescriptorCollection.Count Egenskap

Definition

Hämtar antalet egenskapsbeskrivningar i samlingen.

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

Egenskapsvärde

Antalet egenskapsbeskrivningar i samlingen.

Implementeringar

Exempel

I följande kodexempel används Count egenskapen för att skriva ut antalet egenskaper på button1. Det kräver det button1 och textBox1 har instansierats i ett formulär.

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

Kommentarer

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

Gäller för

Se även