Will a static constructor on a generic class be run for every type you pass into the generic parameter such as this:
class SomeGenericClass<T>
{
static List<T> _someList;
static SomeGenericClass()
{
_someList = new List<T>();
}
}
Are there any draw backs to using this approach?
Yes, the static constructor will be called once for each closed class type (the type created when you specify the type parameters). See the C# 3 specification, §10.12 Static constructors.
and also:
It is also relevant to read §4.4.2 Open and closed types:
This program that you can run yourself demonstrates that the static constructor is called three times, not just once:
Output: