C# - Attributes Questions and Answers
Practice ModeShowing 10 of 38 questions
Q11
Which of the following is the correct way to apply an attribute to an Assembly?
Answer: Option B
Q12
Which of the following is the correct way of applying the custom attribute called Tested which receives two-arguments - name of the tester and the testgrade?
Custom attribute cannot be applied to an assembly.
[assembly: Tested("Sachin", testgrade.Good)]
[Tested("Virat", testgrade.Excellent)]
class customer { /* .... */ }
Custom attribute cannot be applied to a method.
Custom attribute cannot be applied to a class
Answer: Option C
Q13
Attributes can be applied to
Method
Class
Assembly
Namespace
Enum
Answer: Option B
Q14
What is an attribute in C#?
Answer: Option C
Explanation: Attributes are used to add metadata or declarative information to program elements.
Q15
Which namespace contains most of the predefined attributes in C#?
Answer: Option D
Explanation: Most built-in attributes are defined in the System namespace.
Q16
Which symbol is used to apply an attribute in C#?
Answer: Option C
Explanation: Attributes are applied using square brackets [ ].
Q17
Which attribute specifies how a custom attribute can be used?
Answer: Option B
Explanation: AttributeUsage defines valid targets, inheritance, and multiplicity of an attribute.
Q18
Which base class must be inherited to create a custom attribute?
Answer: Option C
Explanation: All custom attributes must inherit from System.Attribute.
Q19
Which target allows an attribute to be applied to a method?
Answer: Option C
Explanation: AttributeTargets.Method specifies that the attribute can be applied to methods.
Q20
Which attribute controls whether multiple instances of the same attribute are allowed?
Answer: Option A
Explanation: AllowMultiple determines whether an attribute can be applied more than once.