Created
September 23, 2020 05:52
-
-
Save aershov24/f987138c9943f8e74f01880ea9dc1d8c to your computer and use it in GitHub Desktop.
Markdium-
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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