Simple Singleton Pattern in C#





5.00/5 (12 votes)
The easiest singleton pattern is the one you used to the lock object itself.Creating any variable as static readonly and initializing it directly (or via a static constructor) will already make it singleton.Also, considering that "lock" clears all the caches, you don't need to declare the...
The easiest singleton pattern is the one you used to the lock object itself.
Creating any variable as
static readonly
and initializing it directly (or via a static
constructor) will already make it singleton.
Also, considering that "lock
" clears all the caches, you don't need to declare the variable as volatile.