Generic Static Constructors
suggest changeA static constructor on a generic type runs once for each closed type, that is, once for each distinct combination of type arguments.
class Animal<T>
{
static Animal()
{
Console.WriteLine(typeof(T).FullName);
}
public static void Yawn() { }
}
Animal<Object>.Yawn();
Animal<String>.Yawn();
This will output:
System.Object System.String
See also How do static constructors for generic types work?
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents