Skip to content

Instantly share code, notes, and snippets.

@DedSec256
Last active June 2, 2022 14:40
Show Gist options
  • Select an option

  • Save DedSec256/cd0972205d3336223ebe58a305eb017e to your computer and use it in GitHub Desktop.

Select an option

Save DedSec256/cd0972205d3336223ebe58a305eb017e to your computer and use it in GitHub Desktop.
public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();
static Singleton()
{
}
private Singleton()
{
...
}
public static Singleton Instance => instance;
}
// Или полностью ленивое
public sealed class Singleton
{
private Singleton()
{
}
public static Singleton Instance { get { return Nested.instance; } }
private class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested()
{
}
internal static readonly Singleton instance = new Singleton();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment