Get events by the specified binding constraints in CSharp

Description

The following code shows how to get events by the specified binding constraints.

Example


using System;/*from ww w  . j a  v a2 s.  c o  m*/
using System.Reflection;
using System.Security;

class EventsSample
{
    public static void Main()
    { 
        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.





















Home »
  C# Tutorial »
    Reflection »




Array
Constructor
Event
Field
Interface
Method
Properties
Type