C# Questions & Answers – Introduction of Reflections

This section of our 1000+ C# MCQs focuses on introduction of reflections in C# Programming Language.

1. Which feature enables to obtain information about the use and capabilities of types at runtime?
a) Runtime type ID
b) Reflection
c) Attributes
d) None of the mentioned
View Answer

Answer: b
Explanation: Reflection is the feature that enables you to obtain information about a type. The term reflection comes from the way the process works: A Type object mirrors the underlying type that it represents. Reflection is a powerful mechanism because it allows us to learn and use the capabilities of types that are known only at runtime.

2. Choose the namespace which consists of classes that are part of .NET Reflection API?
a) System.Text
b) System.Name
c) System.Reflection
d) None of the mentioned
View Answer

Answer: c
Explanation: Many of the classes that support reflection are part of the .NET Reflection API, which is in the System.Reflection namespace.
eg : using System.Reflection;

3. Choose the correct statement about System.Type namespace.
a) Core of the reflection subsystem as it encapsulates a type
b) Consists of many methods and properties that can be used to obtain information about a type at runtime
c) Both Core of the reflection subsystem as it encapsulates a type & Consists of many methods and properties that can be used to obtain information about a type at runtime
d) Only Consists of many methods and properties that can be used to obtain information about a type at runtime
View Answer

Answer: c
Explanation: System.Type is at the core of the reflection subsystem because it encapsulates a type. It contains many properties and methods that you will use to obtain information about a type at runtime.
advertisement
advertisement

4. Choose the class from which the namespace ‘System.Type’ is derived?
a) System.Reflection
b) System.Reflection.MemberInfo
c) Both System.Reflection & System.Reflection.MemberInfo
d) None of the mentioned
View Answer

Answer: b
Explanation: Type is derived from an abstract class called System.Reflection.MemberInfo

5. What does the following property signify?

MemberTypes MemberType

a) Helps in distinguishing kinds of members
b) Property helps in determining if member is a field, method, property or event
c) Both Helps in distinguishing kinds of members & Property helps in determining if member is a field, method, property or event
d) None of the mentioned
View Answer

Answer: c
Explanation: This property obtains the kind of the member. This value indicates if the member is a field, method, property, event, or constructor among others.

6. The property signifies “Obtains a Module object that represents the module (an executable file) in which the reflected type resides”. Choose the property which specifies the following statement?
a) Type DeclaringType
b) int MetadataToken
c) Module Module
d) Type ReflectedType
View Answer

Answer: c
Explanation: By definition.
advertisement

7. Choose the method defined by MemberInfo.
a) GetCustomAttributes()
b) IsDefined()
c) GetCustomeAttributesData()
d) All of the mentioned
View Answer

Answer: d
Explanation: MemberInfo includes two abstract methods: GetCustomAttributes( ) and IsDefined( ). These both relate to attributes. The first obtains a list of the custom attributes associated with the invoking object. The second determines if an attribute is defined for the invoking object. The .NET Framework Version 4.0 adds a method called GetCustomAttributesData(), which returns information about custom attributes.

8. What does the following declaration specify?

advertisement
 MethodInfo[] GetMethods()

a) Returns an array of MethodInfo objects
b) Returns a list of the public methods supported by the type by using GetMethods()
c) Both Returns an array of MethodInfo objects & Returns a list of the public methods supported by the type by using GetMethods()
d) None of the mentioned
View Answer

Answer: c
Explanation: A list of the public methods supported by the type can be obtained by using GetMethods(). It returns an array of MethodInfo objects that describe the methods supported by the invoking type. MethodInfo is in the System.Reflection namespace.

9. What does the following C# code specify?

object Invoke(object obj, object[] parameters)

a) Calling a type using invoke()
b) Any arguments that need to be passed to the method are specified in the array parameters
c) The value returned by the invoked method is returned by Invoke()
d) All of the mentioned
View Answer

Answer: d
Explanation: Here, obj is a reference to the object on which the method is invoked. (For static methods, you can pass null to obj.) Any arguments that need to be passed to the method are specified in the array parameters. If no arguments are needed, parameters must be null. Also, parameters must contain exactly the same number of elements as the number of arguments.

10. What does the following C# method specify?

  Type[] GetGenericArguments()

a) A property defined by MemberInfo
b) Obtains a list of the type arguments bound to a closed constructed generic type
c) The list may contain both type arguments and type parameters
d) All of the mentioned
View Answer

Answer: d
Explanation: The following method Obtains a list of the type arguments bound to a closed constructed generic type or the type parameters if the specified type is a generic type definition. For an open constructed type, the list may contain both type arguments and type parameters.

Sanfoundry Global Education & Learning Series – C# Programming Language.

To practice all featur es of C# programming language, here is complete set on 1000+ Multiple Choice Questions and Answers on C#.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.