G
Guest
I've applied readonly variables to my code where its seemed useful to do so,
such as
readonly string m_name;
public MyClass(string name)
{ m_name = name); }
Where I have had multiple constructors for a class I have had to apply all
the settings to one constructor or set each variable in different
constructors:
public MyClass(string name) : this(name, "")
{ }
public MyClass(string name, string address)
{ m_name = name;
m_address = address; }
However is it possible to set multiple constructors through a method in the
class called by the constructor? Something like:
public MyClass(string name) : this(name, "")
{ }
public MyClass(string name, string address)
{ Initalize(); }
private void Initialize()
{
m_name = name;
m_address = address;
}
such as
readonly string m_name;
public MyClass(string name)
{ m_name = name); }
Where I have had multiple constructors for a class I have had to apply all
the settings to one constructor or set each variable in different
constructors:
public MyClass(string name) : this(name, "")
{ }
public MyClass(string name, string address)
{ m_name = name;
m_address = address; }
However is it possible to set multiple constructors through a method in the
class called by the constructor? Something like:
public MyClass(string name) : this(name, "")
{ }
public MyClass(string name, string address)
{ Initalize(); }
private void Initialize()
{
m_name = name;
m_address = address;
}