PropertyDescriptorCollection.Count Properti

Definisi

Mendapatkan jumlah deskriptor properti dalam koleksi.

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

Nilai Properti

Jumlah deskriptor properti dalam koleksi.

Penerapan

Contoh

Contoh kode berikut menggunakan Count properti untuk mencetak jumlah properti pada button1. Ini mengharuskan dan button1textBox1 telah diinstansiasi pada formulir.

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

Keterangan

Anda dapat menggunakan Count properti untuk mengatur batas perulangan yang melakukan iterasi melalui kumpulan objek. Karena koleksi berbasis nol, pastikan untuk menggunakan Count - 1 sebagai batas atas perulangan.

Berlaku untuk

Lihat juga