Skip to content

Instantly share code, notes, and snippets.

@cgatian
Forked from JesseBuesking/Singleton.cs
Last active December 20, 2015 20:58
Show Gist options
  • Save cgatian/6193655 to your computer and use it in GitHub Desktop.
Save cgatian/6193655 to your computer and use it in GitHub Desktop.
public class Singleton
{
private static readonly Lazy<Singleton> _lazy = new Lazy<Singleton>(
() => new Singleton(), isThreadSafe: true);
public static Singleton Instance
{
get
{
return Singleton._lazy.Value;
}
}
private Singleton()
{
}
}
@cgatian
Copy link
Author

cgatian commented Jan 14, 2014

Modified by removing LazyThreadSafetyMode.ExecutionAndPublication in favor of a specified a named parameter (isThreadSafe) for human readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment