I want to be able to instaniate a class with a public constructor that will by default call a private constructor and I think it is something close to the code below, but it isn't.
public MySQLConnector()
: this MySQLConnector (ConfigurationManager.AppSettings["DBConnection"])
{
}
private MySQLConnector(string dbConnectionString)
{
//code
}
You've almost got it. Just use this(...)
, without the class name:
public MySQLConnector()
: this(ConfigurationManager.AppSettings["DBConnection"])
{
}
This is documented in Using Constructors (C# Programming Guide):
A constructor can invoke another constructor in the same object by using the this keyword. Like base, this can be used with or without parameters, and any parameters in the constructor are available as parameters to this, or as part of an expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With