Use as a template for any singleton classes you require. Instantiate with...
Singleton object = Singleton.Instance;
further information...
Use as a template for any singleton classes you require. Instantiate with...
Singleton object = Singleton.Instance;
further information...
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace Singleton | |
| { | |
| public sealed class Singleton | |
| { | |
| // from: C# in Depth - Implementing the Singleton Pattern in C# | |
| // Url: http://csharpindepth.com/Articles/General/Singleton.aspx | |
| private static readonly Lazy<Singleton> _lazy = | |
| new Lazy<Singleton>(() => new Singleton()); | |
| private Singleton() | |
| { | |
| } | |
| public static Singleton Instance | |
| { | |
| get | |
| { | |
| return _lazy.Value; | |
| } | |
| } | |
| } | |
| } |