Users Online

· Guests Online: 51

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Questions & Answers ? Introduction of Reflections

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

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

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

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.
 

 

 

 

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

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

 

 

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

Answer: c
Explanation: By definition.

 

 

 

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

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?

 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

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

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

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.

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.70 seconds
10,843,342 unique visits