One large difference is that
Student s1 = new Student();
will not compile if there is no default constructor on Student
, whereas
Student s1 = Activator.CreateInstance<Student>();
will compile even if Student
does not have a default constructor. (It will compile, and let you run the program, but if there is no matching constructor you will get an exception, whereas the constructor call will not even compile if the constructor does not exist.)
Similarly, the CreateInstance
call is an implicit use of the class, so, for example, Resharper will not know that you are instantiating it, and might tell you that the class is never instantiated.
As mentioned in other answers, the CreateInstance
call also allows for the use of a generic type parameter:
T s1 = Activator.CreateInstance<T>();
though you would probably be better off using a new
type constraint, since it would give you compile-time assurance that there actually is a constructor to be called.
The Activator.CreateInstance(Type, ...)
overloads are much more useful, however.