public class TestEditor
{
private static TestEditor instance;//如果希望多线程单便应加volatile关键词
private static readonly object syncRoot = new object();
private TestEditor(){}
public static TestEditor GetInstance()
{
if (instance == null)
{
lock (syncRoot)
{
if (instance == null)
{
instance = new TestEditor();
}
}
}
return instance;
}
}
public class SingletonTest
{
public static readonly SingletonTest Instance = new SingletonTest();
private SingletonTest() { }
}
public class SingletonTest
{
public static readonly SingletonTest Instance;
static SingletonTest()
{
Instance = new SingletonTest();
}
private SingletonTest() { }
}