This documentation is archived and is not being maintained.

Type.GetEvents Method ()

Returns all the public events that are declared or inherited by the current Type.

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

virtual array<EventInfo^>^ GetEvents ()
public EventInfo[] GetEvents ()
public function GetEvents () : EventInfo[]
Not applicable.

Return Value

An array of EventInfo objects representing all the public events which are declared or inherited by the current Type. -or- An empty array of type EventInfo, if the current Type does not have public events.

An event is considered public to reflection if it has at least one method or accessor that is public. Otherwise the event is considered private, and you must use BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static (in Visual Basic, combine the values using Or) to get it.

The GetEvents method does not return events in a particular order, such as alphabetical or declaration order. Your code must not depend on the order in which events are returned, because that order varies.

This method can be overridden by a derived class.

The following table shows what members of a base class are returned by the Get methods when reflecting on a type.

Member Type








Yes. A field is always hide-by-name-and-signature.


Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.



Yes. A method (both virtual and non-virtual) can be hide-by-name or hide-by-name-and-signature.

Nested Type




Not applicable

The common type system rule is that the inheritance is the same as that of the methods that implement the property. Reflection treats properties as hide-by-name-and-signature. See note 2 below.

  1. Hide-by-name-and-signature considers all of the parts of the signature, including custom modifiers, return types, parameter types, sentinels, and unmanaged calling conventions. This is a binary comparison.

  2. For reflection, properties and events are hide-by-name-and-signature. If you have a property with both a get and a set accessor in the base class, but the derived class has only a get accessor, the derived class property hides the base class property, and you will not be able to access the setter on the base class.

  3. Custom attributes are not part of the common type system.

If the current Type represents a constructed generic type, this method returns the EventInfo objects with the type parameters replaced by the appropriate type arguments.

If the current Type represents a type parameter in the definition of a generic type or generic method, this method searches the events of the class constraint.

The following example obtains an array of EventInfo objects, gets all the events for a Button class, and displays the event names. To compile the Visual Basic example, use the following command line:

vbc type_getevents1.vb /r:System.Windows.Forms.dll /r:System.dll

#using <System.dll>
#using <System.Windows.Forms.dll>
#using <System.Drawing.dll>

using namespace System;
using namespace System::Reflection;
using namespace System::Security;

int main()
      Type^ myType = System::Windows::Forms::Button::typeid;
      array<EventInfo^>^myEvents = myType->GetEvents();
      Console::WriteLine( "The events on the Button class are: " );
      for ( int index = 0; index < myEvents->Length; index++ )
         Console::WriteLine( myEvents[ index ] );

   catch ( SecurityException^ e ) 
      Console::WriteLine( "SecurityException: {0}", e->Message );
   catch ( ArgumentNullException^ e ) 
      Console::WriteLine( "ArgumentNullException: {0}", e->Message );
   catch ( Exception^ e ) 
      Console::WriteLine( "Exception: {0}", e->Message );

import System.*;
import System.Reflection.*;
import System.Security.*;

class EventsSample
    public static void main(String[] args)
        try {
            // Creates a bitmask based on BindingFlags.
            BindingFlags myBindingFlags = BindingFlags.Instance
                | BindingFlags.Public;
            Type myTypeEvent = System.Windows.Forms.Button.class.ToType();
            EventInfo myEventsBindingFlags[] =
            Console.WriteLine("\nThe events on the Button class with the "
                + "specified BindingFlags are : ");
            for (int index = 0; index < myEventsBindingFlags.length; index++) {
        catch (SecurityException e) {
            Console.WriteLine("SecurityException :" + e.get_Message());
        catch (ArgumentNullException e) {
            Console.WriteLine("ArgumentNullException : " + e.get_Message());
        catch (System.Exception e) {
            Console.WriteLine("Exception : " + e.get_Message());
    } //main
} //EventsSample

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0