Is there a elegant way to pass multiple arguments to a constructor?
This is my constructor:
public _Empresa(string n, string r, string d, int l, string c, string f, string t, string m, string o)
{
e_nombre = n;
e_rfc = r;
e_direccion = d;
e_delegacion = l;
e_cp = c;
e_referencias = f;
e_telefono = t;
e_email = m;
e_observaciones = o;
}
Lately in a windows form I call that constructor
public _Empresa empresa
{
get
{
return new _Empresa(_nombre.Text, _rfc.Text, _direccion.Text, int.Parse(_delegacion.SelectedValue.ToString()), _cp.Text, _referencias.Text, _telefono.Text, _email.Text, _observaciones.Text);
}
}
They aren’t same type so no chance of sending an array. What other options do i have?
If some of those properties are related, you could group them into smaller classes on their own (so you could pass in an instance of that class to the constructor of your class). However that would just spread your initialization to two or three smaller objects, so you should do it only if it makes logical sense for your code, not only to make your constructor more readable.
One thing that may make your code more readable is using named parameters and some indentation:
which would also look better if the parameter names were more self-descriptive