I read about one design of the Singleton class in C # to this excellent resource and decided to go with alternative 4:
public sealed class Singleton1 { static readonly Singleton1 _instance = new Singleton1(); static Singleton1() { } Singleton1() { } public static Singleton1 Instance { get { return _instance; } } }
Now I wonder if this can be rewritten with auto properties like this?
public sealed class Singleton2 { static Singleton2() { Instance = new Singleton2(); } Singleton2() { } public static Singleton2 Instance { get; private set; } }
If this is just a matter of readability, I definitely prefer the second version, but I want everything to be correct.
source share