// Get the method information MethodInfo methodInfo = typeof(MyClass).GetMethod("MyMethod"); // Create an instance of the class MyClass myClass = new MyClass(); // Invoke the method on the instance object result = methodInfo.Invoke(myClass, null);
// Get the method information MethodInfo methodInfo = typeof(MyClass).GetMethod("MyMethod"); // Create an instance of the class MyClass myClass = new MyClass(); // Create an array of arguments object[] args = { "arg1", "arg2" }; // Invoke the method on the instance object result = methodInfo.Invoke(myClass, args);In this example, we get the MethodInfo object for the method named "MyMethod" on the MyClass type. We then create an instance of MyClass and create an array of arguments to pass to the method. We then invoke the method on the instance with the array of arguments. These examples belong to the System.Reflection library.