Share via


Invoke Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Invokes the method or constructor represented by the current instance, using the specified parameters.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

Syntax

'Declaration
Public Function Invoke ( _
    obj As Object, _
    parameters As Object() _
) As Object
public Object Invoke(
    Object obj,
    Object[] parameters
)
public:
Object^ Invoke(
    Object^ obj, 
    array<Object^>^ parameters
)
member Invoke : 
        obj:Object * 
        parameters:Object[] -> Object 
public function Invoke(
    obj : Object, 
    parameters : Object[]
) : Object

Parameters

  • obj
    Type: System. . :: . .Object
    The object on which to invoke the method or constructor. If a method is static, this argument is ignored. If a constructor is static, this argument must be nullNothingnullptrunita null reference (Nothing in Visual Basic) or an instance of the class that defines the constructor.
  • parameters
    Type: array<System. . :: . .Object> [] () [] []
    An argument list for the invoked method or constructor. This is an array of objects with the same number, order, and type as the parameters of the method or constructor to be invoked. If there are no parameters, parameters should be nullNothingnullptrunita null reference (Nothing in Visual Basic).
    If the method or constructor represented by this instance takes a ref parameter (ByRef in Visual Basic), no special attribute is required for that parameter in order to invoke the method or constructor using this function. Any object in this array that is not explicitly initialized with a value will contain the default value for that object type. For reference-type elements, this value is nullNothingnullptrunita null reference (Nothing in Visual Basic). For value-type elements, this value is 0, 0.0, or false, depending on the specific element type.

Return Value

Type: System. . :: . .Object
An object containing the return value of the invoked method, or nullNothingnullptrunita null reference (Nothing in Visual Basic) in the case of a constructor.

Warning

Elements of the parameters array that represent parameters declared with the ref or out keyword may also be modified.

Remarks

This is a convenience method that calls the Invoke(Object, BindingFlags, Binder, array<Object>[]()[][], CultureInfo) method overload, passing Default for invokeAttr and null Nothing nullptr unit a null reference (Nothing in Visual Basic) for binder and culture.

To invoke a static method using its MethodInfo object, pass null Nothing nullptr unit a null reference (Nothing in Visual Basic) for obj.

Note

If this method overload is used to invoke an instance constructor, the object supplied for obj is reinitialized; that is, all instance initializers are executed. The return value is null Nothing nullptr unit a null reference (Nothing in Visual Basic) . If a class constructor is invoked, the class is reinitialized; that is, all class initializers are executed. The return value is null Nothing nullptr unit a null reference (Nothing in Visual Basic) .

If a parameter of the current method is a value type, and the corresponding argument in parameters is null Nothing nullptr unit a null reference (Nothing in Visual Basic) , the runtime passes a zero-initialized instance of the value type.

.NET Framework Security

See Also

Reference

MethodBase Class

System.Reflection Namespace