Singleton Pattern Code Review

Define the Singleton Object

Code Download

  • Download Description:singleton pattern download
  • .NET Framework:3.5
  • .NET Language:C#
  • Date Published:2009-07-01
  • Download Size:8 KB

Code Review

Code Walkthrough

Define the Singleton class with the required getInstance() method used to create a single instance of the class (object).

class Singleton { private static Singleton instance = null; private static Object syncLock = new Object();
public String Item { get; set; }
private Singleton() {}
public static Singleton getInstance() { if (instance == null) { lock (syncLock) { if (instance == null) { Console.WriteLine("****** Creating Singleton instance ******"); instance = new Singleton(); } } } return instance; } }