65.9K
CodeProject is changing. Read more.
Home

Simple Singleton Pattern in C#

starIconstarIconstarIconstarIconstarIcon

5.00/5 (12 votes)

Jul 8, 2011

CPOL
viewsIcon

16942

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.