locked
c# types and creating new instance of class RRS feed

  • 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. 
    • Proposed as answer by mexil Thursday, January 8, 2009 2:11 AM
    • Marked as answer by Harry Zhu Thursday, January 8, 2009 7:40 AM
    Monday, January 5, 2009 11:25 AM
    • Proposed as answer by mexil Thursday, January 8, 2009 2:11 AM
    • Marked as answer by Harry Zhu Thursday, January 8, 2009 7:40 AM
    Monday, January 5, 2009 6:18 AM

All replies

    • Proposed as answer by mexil Thursday, January 8, 2009 2:11 AM
    • Marked as answer by Harry Zhu Thursday, January 8, 2009 7:40 AM
    Monday, 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. 
    • Proposed as answer by mexil Thursday, January 8, 2009 2:11 AM
    • Marked as answer by Harry Zhu Thursday, January 8, 2009 7:40 AM
    Monday, January 5, 2009 11:25 AM