c# 反射简单使用

时间:2023-03-08 20:59:12

类库dll,将生成ExampleLib.dll文件

namespace ExampleLib
{
public class Example
{
public static string FuncA()
{
return "FuncA";
}
public string FuncB()
{
return "FuncB";
}
}
}

反射调用。创建实例并调用示例中的方法

    class Program
{
static void Main(string[] args)
{
dynamic example = Assembly.Load("ExampleLib").CreateInstance("ExampleLib.Example");
Console.WriteLine(example.FuncB());
Console.ReadKey();
}
}