Consider the following code snippet from .NET 4.0 library:
private T[] array;
private static T[] emptyArray;
private int size;
private int version;
static Stack()
{
Stack<T>.emptyArray = new T[0];
}
public Stack()
{
array = Stack<T>.emptyArray;
size = 0;
version = 0;
}
Is there any reason behind initializing value type private fields to default values (size and version in the example above) explicitely other than coding standards of the company?
No, there is not, at least not a technical reason. Perhaps in some cases one might do that to make a point, for example if you have a counter variable of some sort and you want to make clear it starts from zero. But I think even this is a bit questionable.