Sathyaish said:
What is a private constructor, and why would a class have one?
A private constructor is a constructor that can only be used from within the
class itself.
This normally makes the class fairly useless as nothing can actually create
instances of it, but it can be used alongside shared class members to make
sure nothing can instantiate the class but still allow the shared class
members to be used.
You could have a class that has one or more private constructors and also
one or more public constructors. This could allow you to pass internal
values to new instances of the class when it is instantiated by other code
residing within the class (by using a private constructor), but still allow
code outside of the class to create further instances (using a public
constructor).
What are the other kinds of constructors besides:
(1) public constructors; and
(2) parameterized constructors
You can also use Friend constructors. These may be called from anywhere with
your assembly, but cannot be seen or called from outside of the assembly.
These can be useful when you have a single object that creates and returns
instances of other objects from within the same assembly.
And I understand that they are not mutually exclusive of one another.
Indeed -- Public, Private and Friend describe the scope of the constructor,
that is, which other sections of code are able to see the constructor.
Parameterised constructors allow values to be passed into the constructors,
regardless of what the constructor's scope is.
I hope that all makes sense,