Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 16th, 2006, 03:29 AM
Registered User
Join Date: Jul 2006
Location: Tiruppur, TamilNadu, India.
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default private constructor in C#

Hello p2p's

i want to know what is the use of declaring the constructors as private or protected.

Reply With Quote
  #2 (permalink)  
Old August 16th, 2006, 07:08 AM
Wrox Technical Editor
Join Date: Dec 2005
Location: , , Canada.
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts

Private or protected constructors are generally used to restrict instantiation of a class to a single object. This is often done through the Singleton design pattern.

Private constructors can also be useful for:
  classes containing only static utility methods
  classes containing only constants
  type safe enumerations

Links of further interest:
 The Singleton pattern: http://en.wikipedia.org/wiki/Singleton_pattern.
 Private Constructors: http://www.javapractices.com/Topic40.cjp

- Adam Kahtava [http://adam.kahtava.com]
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Returning Nothing from a constructor Imar Pro VB.NET 2002/2003 8 June 29th, 2012 02:00 PM
Constructor nayeem69 .NET Framework 2.0 1 July 17th, 2007 12:33 AM
static constructor sreenu.pocha C# 1 July 26th, 2006 07:21 AM
Constructor ramess C++ Programming 1 March 18th, 2006 07:23 PM
Problem with a constructor Mishkina General .NET 0 September 23rd, 2005 08:26 AM

All times are GMT -4. The time now is 08:07 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.