Microsoft Certified Solutions Developer (MCSD) Certification Practice Test

Disable ads (and more) with a membership for a one time $2.99 payment

Prepare for the Microsoft Certified Solutions Developer (MCSD) Certification Exam. Practice with flashcards and multiple choice questions. Master each topic with hints and insights. Achieve your certification goals!

Each practice test/flash card set has 50 randomly selected questions from a bank of over 500. You'll get a new set of questions each time!

Practice this question and more.


How do you execute a method and get its return value using Reflection?

  1. Invoke the method on the type object

  2. Call the method directly

  3. Use GetMethod only

  4. Check method availability

The correct answer is: Invoke the method on the type object

To execute a method and retrieve its return value using Reflection, you must invoke the method through the type object that represents the class containing the method. Reflection allows you to inspect the metadata of types at runtime, which includes information about methods and their parameters. Once you have accessed the desired method using Reflection, you can invoke it using the appropriate method on the type, typically the `Invoke` method of the `MethodInfo` class. This process involves several steps: first, you would obtain the `Type` of the object. Then, you would use the `GetMethod` function to retrieve the `MethodInfo` object representing the specific method you intend to call. Finally, with the `MethodInfo`, you can invoke the method using `Invoke()`, passing in the instance of the class (if it’s not a static method) and any required parameters, which allows you to execute the method and capture its return value. This option emphasizes the importance of using the type object for invocation, a key aspect of leveraging Reflection in programming.