静态构造函数有什么区别如下:
class GlobalClass
{
public static DataBase dataBase;
static GlobalClass()
{
dataBase= new DataBase(@"Data Source=..;...; User ID=... ;Password=...;");
dataBase.CreateConnection();
}
}
并在全局类中定义静态实例如下:
class GlobalClass
{
public static GlobalClass Globals = new GlobalClass();
public DataBase dataBase;
public GlobalClass()
{
dataBase= new DataBase(@"Data Source=..;...; User ID=... ;Password=...;");
dataBase.CreateConnection();
}
}
每种类型之间有什么区别?哪个更好用?