Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 16th, 2006, 03:29 AM
Registered User
 
Join Date: Jul 2006
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.



[N.Sivakumar]
 
Old August 16th, 2006, 07:08 AM
Wrox Technical Editor
 
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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]





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





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