PropertyDescriptorCollection.Count Właściwość

Definicja

Pobiera liczbę deskryptorów właściwości w kolekcji.

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

Wartość właściwości

Liczba deskryptorów właściwości w kolekcji.

Implementuje

Przykłady

W poniższym przykładzie kodu użyto Count właściwości , aby wydrukować liczbę właściwości w pliku button1. Wymaga to utworzenia button1textBox1 wystąpienia i utworzenia wystąpienia w formularzu.

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

Uwagi

Za pomocą Count właściwości można ustawić limity pętli, która iteruje przez kolekcję obiektów. Ponieważ kolekcja jest oparta na zera, pamiętaj, aby użyć Count - 1 jej jako górnej granicy pętli.

Dotyczy

Zobacz też