Calling this method is equivalent to calling the constructor on the class with no arguments (the default constructor). For example if the Type object represents the String class, calling CreateInstance() is equivalent to invoking the default String constructor. This would fail, however (a MissingMethodException would be thrown) because String does not have a default constructor.
Note: Access restrictions are ignored for fully trusted code. That is, private constructors, methods, fields, and properties can be accessed and invoked via Reflection whenever the code is fully trusted.
[Visual Basic] Overloads Public Shared Function CreateInstance( _ ByVal type As Type _ ) As Object [C#] public static object CreateInstance( Type type ); [C++] public: static Object* CreateInstance( Type* type ); [JScript] public static function CreateInstance( type : Type ) : Object;
A reference to the newly created object.
Exception Type | Condition |
---|---|
MissingMethodException | If no default constructor exists for the type. |
Activator Class | Activator Members | System Namespace | Activator.CreateInstance Overload List