I've been programming in C# and Java recently and I am curious what people would consider the best practice concerning when you should initialize your classes fields?
Should you do it at declaration?:
public class Die
{
private int topFace = 1;
private Random myRand = new Random();
public void Roll()
{
// ....
}
}
or in a constructor..
public class Die
{
private int topFace;
private Random myRand;
public Die()
{
topFace = 1;
myRand = new Random();
}
public void Roll()
{
// ...
}
}
I'm really curious what some of you veterans think is the best practice.. I want to be consistent and stick to one approach.