Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

PropertyDescriptorCollection.Count Property

Gets the number of property descriptors in the collection.

[Visual Basic]
Public ReadOnly Property Count As Integer
[C#]
public int Count {get;}
[C++]
public: __property int get_Count();
[JScript]
public function get Count() : int;

Property Value

The number of property descriptors in the collection.

Remarks

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.

Example

[Visual Basic, C#, C++] The following example uses the Count property to print the number of properties on button1. It assumes that button1 and textBox1 have been instantianted on a form.

[Visual Basic] 
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


[C#] 
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();
 }


[C++] 
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();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

PropertyDescriptorCollection Class | PropertyDescriptorCollection Members | System.ComponentModel Namespace | PropertyDescriptor | TypeDescriptor

Show:
© 2015 Microsoft