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) Exam with comprehensive quizzes, flashcards, and multiple-choice questions. Each query includes hints and clear explanations to help you succeed. Get exam-ready today!

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 can you create an instance of a DataTable using Reflection?

  1. DataTable dt = new DataTable();

  2. DataTable dt = Assembly.CreateInstance("System.Data.DataTable");

  3. Assembly assembly = Assembly.Load("System.Data"); dt = (DataTable)assembly.CreateInstance("System.Data.DataTable");

  4. DataTable dt = Activator.CreateInstance(typeof(DataTable));

The correct answer is: Assembly assembly = Assembly.Load("System.Data"); dt = (DataTable)assembly.CreateInstance("System.Data.DataTable");

Creating an instance of a DataTable using Reflection typically involves utilizing the functionality provided by the Assembly class to load the specific assembly containing the desired type, and then using that assembly to create an instance of the type. In this context, option C is the most appropriate method for achieving this, as it explicitly demonstrates the process of loading the desired assembly and then calling the CreateInstance method to instantiate the DataTable. When you load the assembly "System.Data" using Assembly.Load, you access the relevant types defined in that assembly. Once the assembly containing DataTable is loaded, calling CreateInstance with the fully qualified name of the DataTable type allows you to reflectively generate an instance of it. This encapsulates the essence of using Reflection to create an object: you are dynamically invoking the behavior of classes at runtime based on the types and methods defined in the loaded assembly. The other choices do not fully adhere to the principles of Reflection or do not demonstrate the intended use of the Assembly and its methods. For instance, simply creating an instance of DataTable directly (Choice A) does not involve Reflection and is a straightforward instantiation. While Choice B suggests using Assembly to create an instance, it lacks the context of loading the assembly properly, as it does not reference