Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

PropertyDescriptorCollection.Count Property


Gets the number of property descriptors in the collection.

Namespace:   System.ComponentModel
Assembly:  System (in System.dll)

public int Count { get; }

Property Value

Type: System.Int32

The number of property descriptors in the collection.

You can use the Count property to set the limits of a loop that iterates through a collection of objects. Because the collection is zero-based, be sure to use Count - 1 as the upper boundary of the loop.

The following code example uses the Count property to print the number of properties on button1. It requires that button1 and textBox1 have been instantiated on a form.

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

.NET Framework
Available since 1.1
Return to top
© 2017 Microsoft