Muokkaa

Jaa


EventDescriptorCollection.Count Property

Definition

Gets the number of event descriptors in the collection.

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

Property Value

The number of event descriptors in the collection.

Implements

Examples

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();
   }
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();
 }
Private Sub GetCount()
    ' Creates a new collection and assigns it the events for button1.
    Dim events As EventDescriptorCollection = TypeDescriptor.GetEvents(button1)
    
    ' Prints the number of events on button1 in a text box.
    textBox1.Text = events.Count.ToString()
End Sub

Remarks

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.

Note

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.

Applies to

See also