













1
using System;
2
using System.Reflection;
3
4
namespace Test
5
{
6
7
8
public class A
9
{
10
public virtual string method(int i) { return i.ToString(); }
11
}
12
13
public class B
14
{
15
public virtual string method(int i, int o) { return i.ToString()+o.ToString(); }
16
}
17
18
class Mymethodinfo
19
{
20
public static void Main()
21
{
22
A MyA = new A();
23
B MyB = new B();
24
25
// Get the Type and MethodInfo.
26
Type MyTypea = typeof(A);//Type.GetType("A");
27
MethodInfo Mymethodinfoa = MyTypea.GetMethod("method");
28
29
Type MyTypeb = typeof(B);//Type.GetType("B");
30
31
MethodInfo Mymethodinfob = MyTypeb.GetMethod("method");
32
33
// Get and display the Invoke method.
34
Console.Write("\nFirst method - " + MyTypea.FullName +
35
" returns " + Mymethodinfoa.Invoke(MyA, new object[] { 100}));
36
Console.Write("\nSecond method - " + MyTypeb.FullName +
37
" returns " + Mymethodinfob.Invoke(MyB, new object[] { 100, 200 }));
38
Console.Read();
39
}
40
}
41
42
}
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。