It is guaranteed that the static field is initialized before you receive it. (And also, if there is also a static constructor, then all static fields will be initialized before the static constructor starts.)
For generic classes, static initialization works on the basis of each type, so the Container<int> acts as if it were a completely different class for the Container<double> . This is really true for all the static parts of the universal class - each type gets its own "copy".
An example will show this last point more clearly:
static class Foo<T> { static int count = 0; public static int Increment() { return ++count; } } public class Program { public static void Main() { Console.WriteLine(Foo<int>.Increment()); Console.WriteLine(Foo<int>.Increment()); Console.WriteLine(Foo<double>.Increment()); } }
Output:
1 2 1
source share