If you take a look inside Stack<T>
class from .NET 4.0, you will notice that there is an "emptyArray" private static field which is used inside constructors to initialize a real "array" private field.
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;
}
Why not just put this.array = new T[0];
? And also why there are placed initialization strokes for size and version fields, if you omit those lines they will be initialied to default values (0) anyway.