62,040
社区成员
发帖
与我相关
我的任务
分享
public class Singleton<T>
{
private static T instance;
public static T Instance()
{
if (instance == null)
{
instance = Activator.CreateInstance<T>();
}
return instance;
}
}
protected void Page_Load(object sender, EventArgs e)
{
Button btn = Singleton<Button>.Instance();
btn.id="xxx";
btn.width=xxx;
TextBox tb = Singleton<TextBox>.Instance();
tb.id="xxx";
tb.width=xxx;
this.form1.Controls.Add(btn);
this.form1.Controls.Add(tb);
}