PropertyDescriptorCollection.Count Eigenschaft

Definition

Ruft die Anzahl der Eigenschaftenbezeichner in der Auflistung ab.

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

Eigenschaftswert

Die Anzahl der Eigenschaftenbezeichner in der Auflistung.

Implementiert

Beispiele

Im folgenden Codebeispiel wird die Count -Eigenschaft verwendet, um die Anzahl der Eigenschaften für zu button1drucken. Es erfordert, dass button1 und textBox1 auf einem Formular instanziiert wurden.

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();
   }
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();
 }
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

Hinweise

Sie können die Count -Eigenschaft verwenden, um die Grenzwerte einer Schleife festzulegen, die eine Auflistung von -Objekten durchläuft. Da die Auflistung nullbasiert ist, stellen Sie sicher, dass Sie als obere Grenze der Schleife verwenden Count - 1 .

Gilt für:

Weitere Informationen