C# Type GetEvent(String)
Description
Type GetEvent(String)
returns the EventInfo object
representing the specified public event.
Syntax
Type.GetEvent(String)
has the following syntax.
public EventInfo GetEvent(
string name
)
Parameters
Type.GetEvent(String)
has the following parameters.
name
- The string containing the name of an event that is declared or inherited by the current Type.
Returns
Type.GetEvent(String)
method returns The object representing the specified public event that is declared or inherited
by the current Type, if found; otherwise, null.
Example
The following example creates an EventInfo object and gets the event for a button class for the specified event.
using System;/*from w ww.j a v a2 s. c o m*/
using System.Reflection;
using System.Security;
class MyEventExample
{
public static void Main()
{
Type myType = typeof(System.Windows.Forms.Button);
EventInfo myEvent = myType.GetEvent("Click");
if(myEvent != null)
{
Console.WriteLine("Looking for the Click event in the Button class.");
Console.WriteLine(myEvent.ToString());
}
else
Console.WriteLine("The Click event is not available in the Button class.");
}
}
The code above generates the following result.