Skip to content

Instantly share code, notes, and snippets.

@aershov24
Created September 23, 2020 06:11
Show Gist options
  • Save aershov24/b9d921c5218d49c4b58feacb91dc1308 to your computer and use it in GitHub Desktop.
Save aershov24/b9d921c5218d49c4b58feacb91dc1308 to your computer and use it in GitHub Desktop.
Markdium-60 .NET Interview Questions Devs Must Focus On (ANSWERED)
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