Windows apps
Collapse the table of content
Expand the table of content
Information
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.

EventDescriptorCollection::Count Property

 

Gets the number of event descriptors in the collection.

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

public:
property int Count {
	int get();
}

Property Value

Type: System::Int32

The number of event descriptors in the collection.

The Count property can be used 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.

System_CAPS_noteNote

The HostProtectionAttribute attribute applied to this class has the following Resources property value: Synchronization. The HostProtectionAttribute does not affect desktop applications (which are typically started by double-clicking an icon, typing a command, or entering a URL in a browser). For more information, see the HostProtectionAttribute class or SQL Server Programming and Host Protection Attributes.

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

private:
   void GetCount()
   {
      // Creates a new collection and assigns it the events for button1.
      EventDescriptorCollection^ events = TypeDescriptor::GetEvents( button1 );

      // Prints the number of events on button1 in a text box.
      textBox1->Text = events->Count.ToString();
   }

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