Advertisement
akosiraff

Download Week 2 Learning Team_answers

Jun 20th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/week-2-learning-team_answers/
  3. 1. You are given an assignment to create a code generator to automate the task of creating
  4. repetitive code. Which namespace contains the types needed to generate code?
  5. a. System.Reflection
  6. b. CodeDom
  7. c. Reflection
  8. d. System.CodeDom
  9. 2. Which code can create a lambda expression?
  10. a. delegate x = x => 5 + 5;
  11. b. delegate MySub(double x); MySub ms = delegate(double y) { y *
  12. y; }
  13. c. x => x * x;
  14. d. delegate MySub(); MySub ms = x * x;
  15. 3. You are consulting for a company called Contoso and are taking over an application that
  16. was built by a third-party software company. There is an executable that is currently not
  17. working because it is missing a DLL file that is referenced. How can you figure out which
  18. DLL files the application references?
  19. a. Create an instance of the Assembly class, load the assembly, and iterate through the
  20. ReferencedAssemblies property.
  21. b. Create an instance of the Assembly class, load the assembly, and call the
  22. GetReferencedAssemblies method.
  23. c. Create an instance of the Assembly class, load the assembly, and iterate through the
  24. Modules property.
  25. d. Create an instance of the Assembly class, load the assembly, and call the
  26. GetModulesReferenced method.
  27. 354 | CHAPTER 8 REFLECTION, CUSTOM ATTRIBUTES, THE CODEDOM, AND LAMBDA EXPRESSIONS
  28. 4. You are a developer for a finance department and are building a method that uses reflection
  29. to get a reference to the type of object that was passed as a parameter. Which syntax can be
  30. used to determine an object’s type?
  31. a. Type myType = typeof(myParameter);
  32. b. Object myObject = myParameter.GetType(object);
  33. c. Object myObject = typeof(myParameter);
  34. d. Type myType = myParameter.GetType();
  35. 5. You are asked to create a custom attribute that has a single property, called Version, that
  36. allows the caller to determine the version of a method. Which code can create the attribute?
  37. a. class MyCustomAttribute :System.Reflection.Attribute
  38. { public string Version { get; set; } }
  39. b. class MyCustomAttribute : System.Attribute
  40. { public string Version { get; set; } }
  41. c. class MyCustomAttribute : System.AttributeUsage
  42. { public string Version { get; set; } }
  43. d. class MyCustomAttribute : System.ClassAttribute
  44. { public string Version { get; set; } }
  45. 6. Which class in the System.Reflection namespace would you use if you want to determine
  46. all the classes contained in a DLL file?
  47. a. FileInfo
  48. b. Assembly
  49. c. Type
  50. d. Module
  51. 7. Which method of the Assembly class allows you to get all the public types defined in
  52. the Assembly?
  53. a. DefinedTypes
  54. b. Types
  55. c. GetExportedTypes
  56. d. GetModules
  57. 8. Which property of the Assembly class returns the name of the assembly?
  58. a. Name
  59. b. FullyQualifiedName
  60. c. Location
  61. d. FullName
  62. Chapter Test Questions | 355
  63. 9. Which method of the Assembly class returns an instance of the current assembly?
  64. a. GetExecutingAssembly
  65. b. GetAssembly
  66. c. GetCurrentAssembly
  67. d. Assembly
  68. 10. Which syntax will Load an Assembly? (Choose all that apply)
  69. a. Assembly.Load(“System.Data, Version=4.0.0.0, Culture=neutral,
  70. PublicKeyToken=b77a5c561934e089″);
  71. b. Assembly.LoadFrom(@”c:\MyProject\Project1.dll”);
  72. c. Assembly.LoadFile(@”c:\MyProject\Project1.dll”);
  73. d. Assembly.ReflectionOnlyLoad((“System.Data, Version=4.0.0.0,
  74. Culture=neutral, PublicKeyToken=b77a5c561934e089″);
  75. 11. Which method should you call if you want the .NET Framework to look in the load-context
  76. to load an Assembly?
  77. a. ReflectionOnlyLoad
  78. b. LoadFrom
  79. c. Load
  80. d. LoadFromContext
  81. 12. Which method should you call if you want the .NET Framework to look in the load-from
  82. context?
  83. a. ReflectionOnlyLoad
  84. b. LoadFrom
  85. c. Load
  86. d. LoadFromContext
  87. 13. Which line creates an instance of a DataTable using reflection?
  88. a. myAssembly.CreateInstance(“System.Data.DataTable”);
  89. b. DataTable.GetType();
  90. c. typeof(“System.Data.DataTable”);
  91. d. myType.CreateInstance(“System.Data.DataTable”);
  92. 356 | CHAPTER 8 REFLECTION, CUSTOM ATTRIBUTES, THE CODEDOM, AND LAMBDA EXPRESSIONS
  93. 14. Which class would you create if you wanted to determine all the properties contained in a
  94. class using reflection?
  95. a. Assembly
  96. b. Class
  97. c. Property
  98. d. Type
  99. 15. How can you determine if a class is public or private?
  100. a. Create an instance of the Type class using the typeof keyword and then examine the
  101. IsPublic property of the Type variable.
  102. b. Create an instance of the Type class using the typeof keyword and then examine the
  103. IsPrivate property of the Type variable.
  104. c. Create an instance of the class within a try catch block and catch the exception if
  105. you cannot create an instance of the class.
  106. d. Create an instance of the class and check the IsPublic property.
  107. 16. Which class in the System.Reflection namespace is used to represent a field defined in
  108. a class?
  109. a. PropertyInfo
  110. b. FieldInfo
  111. c. Type
  112. d. EventInfo
  113. 17. Which property of the Type class can you use to determine the number of dimension for
  114. an array?
  115. a. GetDimension
  116. b. GetRank
  117. c. GetDimensions
  118. d. GetArrayRank
  119. 18. Which statement will returns a private, instance field called “myPrivateField” using
  120. reflection? Assume the myClass variable is an instance of a class.
  121. a. myClass.GetType().GetField(“myPrivateField”,
  122. BindingFlags.NonPublic | BindingFlags.Instance)
  123. b. myClass.myPrivateField
  124. c. myClass.GetType().GetField(“myPrivateField”)
  125. d. myClass. GetType().GetField(“myPrivateField”,
  126. BindingFlags.NonPublic & BindingFlags.Instance)
  127. Additional Reading and Resources | 357
  128. 19. Which method of the MethodInfo class can be used to execute the method?
  129. a. Execute
  130. b. Invoke
  131. c. Call
  132. d. Load
  133. 20. Which statement uses reflection to execute the method and passes in two parameters given
  134. the following code block?
  135. MyClass myClass = new MyClass();
  136. MethodInfo myMethod = typeof(MyClass).GetMethod(“Multiply”);
  137. a. myMethod.Execute(myClass, new object[] { 4, 5 });
  138. b. myMethod.Execute(MyClass, new object[] { 4, 5 });
  139. c. myMethod.Invoke(myClass, new object[] { 4, 5 });
  140. d. myMethod.Invoke(MyClass, new object[] { 4, 5 });
  141.  
  142. Download: http://solutionzip.com/downloads/week-2-learning-team_answers/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement