using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ReflectFromStringToClass
{
class Program
{
static void Main(string[] args)
{
string str = "A";
Type type = Type.GetType(new Program().GetType().Namespace+"."+str,true,true);
var temp= Activator.CreateInstance(type);
A a = temp as A;
a.PintA();
}
}
public class A
{
public A()
{
}
public void PintA()
{
Console.WriteLine("A");
}
}
}
C#如何使用反射实现通过字符串创建类
最新推荐文章于 2023-04-19 14:42:18 发布