Skip to content

Instantly share code, notes, and snippets.

@aershov24
Created September 23, 2020 05:52
Show Gist options
  • Save aershov24/f987138c9943f8e74f01880ea9dc1d8c to your computer and use it in GitHub Desktop.
Save aershov24/f987138c9943f8e74f01880ea9dc1d8c to your computer and use it in GitHub Desktop.
Markdium-
public sealed class Singleton
{
// Because Singleton's constructor is private, we must explicitly
// give the Lazy a delegate for creating the Singleton.
static readonly Lazy instanceHolder =
new Lazy(() => new Singleton());
Singleton()
{
// Explicit private constructor to prevent default public constructor.
...
}
public static Singleton Instance => instanceHolder.Value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment