Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Microsoft's Singleton Example 1

Status
Not open for further replies.

bernardmanning

Programmer
Oct 14, 2003
61
0
0
GB
Hi, I've been looking at the singleton example as detailed on MS patterns and practice webpages ;


I've been looking at the .NET enhanced version of the singleton pattern and have a quick question.

The class looks this ;

Code:
sealed class SingletonCounter 
	{
	public static readonly SingletonCounter Instance = new SingletonCounter();
	
	private long Count = 0;
	
	private SingletonCounter(){} 
	
	public long NextValue() 
	{
		return ++Count;
	}
}

My question is this ;

What's the purpose of the line of code ?

Code:
private SingletonCounter(){}

Anybody shed any light on this?

Thanks, Bernard......
 
<slaps bernarmannings head some more>

Christiaan Baes
Belgium

I just like this --> [Wiggle] [Wiggle]
 
Bernard,

So you've given up stand up now then for a career in software development? ;)



Mike
 
it's the constructor for the class..isn't it?
More importantly - it's the Private instance constructor. So this means that no one can do a new on it -- they must go through the Instance member.

Chip H.


____________________________________________________________________
Donate to Katrina relief:
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top