Answered by:
c# types and creating new instance of class

Question
-
I recently took a test on c#. I've been struggling to find the correct answer to this question for 2 days now:
Which one of the following types allows you to create a new instance of a class?
A) CreateObject
B) MemberInfo
C) TypeToken
D) FieldInfo
E) ConstructorInfo
Choice (A) is a VB method. Choice (C) is a structure. That leaves (B), (D), and (E) - all of which are classes that can be inherited from. Am I totally missing the point of the question?Monday, January 5, 2009 5:38 AM
Answers
-
U can use this in case of reflection.For eg: u may develop an application where u will plug in several classes later (after deployment)And for avoiding recomplilation u can just deploy ur dll and give the information to the initiator class (say thru an XML file) to load the new dll.Monday, January 5, 2009 11:25 AM
-
Check out the ConstructorInfo.Invoke method:
http://msdn.microsoft.com/en-us/library/system.reflection.constructorinfo.invoke.aspxMonday, January 5, 2009 6:18 AM
All replies
-
Check out the ConstructorInfo.Invoke method:
http://msdn.microsoft.com/en-us/library/system.reflection.constructorinfo.invoke.aspxMonday, January 5, 2009 6:18 AM -
Ohh, ok. The return type is an instance of the class - exactly what the question is asking. Where would this be used instead of the common "new" operator?
ps thanks for the help!Monday, January 5, 2009 6:28 AM -
U can use this in case of reflection.For eg: u may develop an application where u will plug in several classes later (after deployment)And for avoiding recomplilation u can just deploy ur dll and give the information to the initiator class (say thru an XML file) to load the new dll.Monday, January 5, 2009 11:25 AM