I implemented the Singleton pattern as follows:
public sealed class MyClass {
...
public static MyClass Instance {
get { return SingletonHolder.instance; }
}
...
static class SingletonHolder {
public static MyClass instance = new MyClass ();
}
}
From Googling to implement C # Singleton, it doesn't look like it's the usual way to do something in C #. I found one such implementation, but the SingletonHolder class was not static and included an explicit (empty) static constructor.
Is this a valid, lazy, thread safe way to implement the Singleton pattern? Or am I missing something?
source
share