vendredi 27 mars 2015

Should I initialize a member variable in declaration when it is initialized by a constructor parameter?


Which is recommended:



class Foo
{
public X x = new X();
public Foo(X _x)
{
x = _x;
}
}


Or



class Foo
{
public X x;
public Foo(X _x)
{
x = _x;
}
}


Please note in the second version, it is probable that I introduce other constructors where x may not be initialized!





Aucun commentaire:

Enregistrer un commentaire