// The following example uses instances of classes in
// the System.Reflection namespace to discover an event argument type.
using System;
using System.Reflection;
public delegate void MyDelegate(int i, string j);
public class MainClass
{
public event MyDelegate ev;
public static void Main()
{
Type delegateType = typeof(MainClass).GetEvent("ev").EventHandlerType;
MethodInfo invoke = delegateType.GetMethod("Invoke");
ParameterInfo[] pars = invoke.GetParameters();
foreach (ParameterInfo p in pars)
{
Console.WriteLine(p.ParameterType);
}
Console.Read();
}
}
// The example displays the following output:
// system.int32
// system.string
事件参数类型
示例代码展示了如何使用System.Reflection命名空间中的类来发现事件参数类型,输出结果为int32和string。