/ Published in: C#
Here's an implementation of a thread safe singleton
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public sealed class MySingleton { private static MySingleton instance; private MySingleton() { // initialize members here } public static MySingleton Instance { get { if (instance == null) { lock (sync) { if (instance == null) } } return instance; } } public void SayHello() { Console.WriteLine("Hello!"); } }