Skip to content

Instantly share code, notes, and snippets.

@aershov24
Created September 23, 2020 06:14
Show Gist options
  • Save aershov24/89c6cc45ce0b8f85ff675cf8ad696dcc to your computer and use it in GitHub Desktop.
Save aershov24/89c6cc45ce0b8f85ff675cf8ad696dcc 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