M
mjduncan
Why does the generic constraint new() use Activator<T>.CreateInstance
instead of new T()?
An example
public class Foo<T> : where T : class, new()
{
T objectValue = new T();
public foo() {}
}
If you look at Lutz's reflector you will get something like
T objectValue = Activator<T>.CreateInstance() in place of T
objectValue = new T();
Using the Activator class is obviously slower and unintuitive to me,
so why does the framework compile my code using
Activator<T>.CreateInstance() instead of new T()?
instead of new T()?
An example
public class Foo<T> : where T : class, new()
{
T objectValue = new T();
public foo() {}
}
If you look at Lutz's reflector you will get something like
T objectValue = Activator<T>.CreateInstance() in place of T
objectValue = new T();
Using the Activator class is obviously slower and unintuitive to me,
so why does the framework compile my code using
Activator<T>.CreateInstance() instead of new T()?