I found some time ago (and I want to confirm again) that if you declare a class level variable, you should not call its constructor until you call the constructor or load the class. The reason was performance - but are there other reasons to do this or not? Are there exceptions to this rule?
, that is: this is what I do based on what I consider to be best practice:
public class SomeClass
{
private PersonObject _person;
public SomeClass()
{
_person = new PersonObject("Smitface");
}
}
opposite:
public class SomeClass
{
private PersonObject _person = new PersonObject("Smitface");
public SomeClass()
{
}
}
source
share