C# 利用泛型创建有参对象
/// <summary>
/// 利用泛型创建对象
/// </summary>
/// <typeparam name="T"></typeparam>
private T NewObj<T>() where T : class
{
Session session = EstateConHandler.Instance.TargetSession;
T rt = Create<T>(session);
return rt;
}
static T Create<T>(Session session)
{
return (T)Activator.CreateInstance(typeof(T), new object[] { session });
}
private T NewObj<T>() where T : class
{
string str = "fsdfs";
T rt = Create<T>(str);
return rt;
}
static T Create<T>(string str)
{
return (T)Activator.CreateInstance(typeof(T), new object[] { str});
}
```
本文标题:C# 利用泛型创建有参对象
本文链接:https://www.haomeiwen.com/subject/lguoxqtx.html
网友评论