If I define a class with a private default constructor and a public constructor that has parameters, how can I access the private constructor?
public class Bo
There are several ways around this issue:
One: Make the constructor public. If you need to access it from outside the class why is it private (it might be that you only want to access the private constructor for testing, in which case this is a valid issue).
Two: Make the constructor protected, then access it through a derived class:
public class Bob
{
public String Surname { get; set; }
protected Bob()
{ }
public Bob(string surname)
{
Surname = surname;
}
}
public class Fred : Bob
{
public Fred()
: base()
{
}
}
Three: Use reflection (as shown by jgauffin).