Possible Duplicate:
Best Practice: Initialize class fields in constructor or at declaration?
Most of the time, I see the way of initializing a variable like this
public class Test
{
private int myIntToInitalize;
public Test()
{
myIntToInitalize = 10;
}
}
From my perspective, this is the most general way of initializing a variable. Most of the code in books, blogs and also internal implementations of .NET are equivalent to my example.
Recently I saw people doing the initialization directly, so without setting the value in the constructor.
public class Test
{
private int myIntToInitalize = 10;
}
In point of view, there is not difference whether initialize and declare a variable or initialize the variable in the constructor.
Apart from the best practices and the length of code lines, where are the benefits of initialize a variable directly and are there subtle differences?