Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Linq;
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Main: {0}", DateTime.Now.TimeOfDay);
- Console.WriteLine("Singleton: {0}", Singleton.text);
- Singleton singleton = Singleton.GetInstance();
- Console.WriteLine("Date: {0}", singleton.Date);
- Console.ReadLine();
- }
- }
- class Singleton
- {
- public static string text = "Hello";
- public string Date{get; private set;}
- private Singleton()
- {
- Console.WriteLine("Singleton ctor: {0}", DateTime.Now.TimeOfDay);
- this.Date = DateTime.Now.TimeOfDay.ToString();
- }
- public static Singleton GetInstance()
- {
- Console.WriteLine("Get instance: {0}", DateTime.Now.TimeOfDay);
- return Nested.instance;
- }
- private class Nested
- {
- static Nested(){}
- internal static readonly Singleton instance = new Singleton();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement