C# 创建对象的方法

1.实例化方法,也就是new();

//where T:new () 表示T必须有构造函数
public static T Create<T> where T:new ()
{
    return T();
}

2.Activator创建实例;

public static T Act_Create<T>()
{
    return Activator.CreateInstance<T>();
}

3.反射创建实例;

//strPath:.dll 路径,strName 类名
public static T Ass_Create<T>()
{
    return (T)Assembly.Load(strPath).CreateInstance(strName);   
}

 其中:第1,2个效率高,第3个由于是反射,效率略低。

原文地址:https://www.cnblogs.com/itsone/p/10299026.html