Export (0) Print
Expand All

AttributeCollection.Count Property

Gets the number of attributes.

[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 attributes.

Remarks

You can use the Count property to set the limits of a loop that iterates through a collection of objects. If 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 in a text box. It assumes that button1 and textBox1 have been created on a form.

[Visual Basic] 
Private Sub GetCount
    ' Creates a new collection and assigns it the attributes for button 1.
    Dim attributes As AttributeCollection
    attributes = TypeDescriptor.GetAttributes(button1)
    ' Prints the number of items in the collection.
    textBox1.Text = attributes.Count.ToString
End Sub

[C#] 
private void GetCount() {
    // Creates a new collection and assigns it the attributes for button1.
    AttributeCollection attributes;
    attributes = TypeDescriptor.GetAttributes(button1);
 
    // Prints the number of items in the collection.
    textBox1.Text = attributes.Count.ToString();
 }


[C++] 
private:
    void GetCount() 
    {
        // Creates a new collection and assigns it the attributes for button1.
        AttributeCollection* attributes;
        attributes = TypeDescriptor::GetAttributes( button1 );
     
        // Prints the number of items in the collection.
        textBox1->Text = __box( attributes->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

AttributeCollection Class | AttributeCollection Members | System.ComponentModel Namespace | Attribute

Show:
© 2014 Microsoft