Skip to content

Instantly share code, notes, and snippets.

@hamishnorton
Last active November 24, 2018 19:40
Show Gist options
  • Save hamishnorton/916bf20924c652b8c9712247f3b83c32 to your computer and use it in GitHub Desktop.
Save hamishnorton/916bf20924c652b8c9712247f3b83c32 to your computer and use it in GitHub Desktop.
Singleton Pattern #CSharp #NET
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;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment