Click here to Skip to main content
15,895,746 members
Articles / Web Development / ASP.NET

Question on Private Constructor

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
25 Jan 2013CPOL 0  
A private constructor can occasionally be used in .Net.An example could be to generate a singleton class - a class which has only instance.For e.g.class A{ static A o; private A() { } public static A getinstance() { if (o == null) { return o =...

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
25 Jan 2013Sergey Alexandrovich Kryukov
Private constructor is used to disable construction of a class using a constructor. It makes sense for a non-static class, of course. Let's set aside static constructors: they do not allow access modifiers at all, and are always treated as private. Here is why: if no constructors defined,...
Please Sign up or sign in to vote.
25 Jan 2013Prosan
look Private constructor[^]
Please Sign up or sign in to vote.
25 Jan 2013VISHWAS KAPTE 3 alternatives  
PRIVATE Constructor is use in .net or Not?if YES then in Which Situation we use PRIVATE Constructor? give me one example?

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India

Comments and Discussions