singleton-theory.cs - // Public static property to get the...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Sheet1 Page 1 using System class SingletonPattern { // Singleton Pattern Judith Bishop Dec 2006 // The public property protects the private constructor public sealed class Singleton { // Private Constructor Singleton() { } // Private object instantiated with private constructor static readonly Singleton instance = new Singleton()
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Public static property to get the object public static Singleton UniqueInstance { get { return instance } } } static void Main() { Singleton s1 = Singleton.UniqueInstance Singleton s2 = Singleton.UniqueInstance if (s1 == s2) { Console.WriteLine("Objects are the same instance") } } }...
View Full Document

Ask a homework question - tutors are online