C# Type GetEvents()
Description
Type GetEvents()
returns all the public events that are
declared or inherited by the current Type.
Syntax
Type.GetEvents()
has the following syntax.
public virtual EventInfo[] GetEvents()
Returns
Type.GetEvents()
method returns
Example
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
//www.ja va 2 s.com
using System;
using System.Reflection;
using System.Security;
class EventsSample
{
public static void Main()
{
// Creates a bitmask based on BindingFlags.
BindingFlags myBindingFlags = BindingFlags.Instance | BindingFlags.Public;
Type myTypeEvent = typeof(System.Windows.Forms.Button);
EventInfo[] myEventsBindingFlags = myTypeEvent.GetEvents(myBindingFlags);
Console.WriteLine("\nThe events on the Button class with the specified BindingFlags are : ");
for (int index = 0; index < myEventsBindingFlags.Length; index++)
{
Console.WriteLine(myEventsBindingFlags[index].ToString());
}
}
}
The code above generates the following result.