C# - Attributes Questions and Answers
Practice ModeShowing 10 of 38 questions
Q21
Which attribute indicates that a class should not be inherited?
Answer: Option C
Explanation: sealed prevents a class from being inherited, though it is not an attribute.
Q22
Which attribute marks a program element as outdated?
Answer: Option C
Explanation: Obsolete warns that a member should no longer be used.
Q23
What happens when an Obsolete attribute is marked as error = true?
Answer: Option C
Explanation: Setting error = true causes a compilation error when used.
Q24
Which attribute hides a public member from IntelliSense?
Answer: Option B
Explanation: EditorBrowsable controls visibility in IntelliSense.
Q25
Which attribute specifies a method that should run before a test?
Answer: Option C
Explanation: TestInitialize is used in unit testing frameworks.
Q26
Which reflection class is commonly used to read attributes at runtime?
Answer: Option B
Explanation: The Type class is used with reflection to retrieve attributes.
Q27
Which method retrieves attributes applied to a program element?
Answer: Option C
Explanation: GetCustomAttributes() is used to obtain attribute instances.
Q28
Which attribute indicates a method does not return a value?
Answer: Option C
Explanation: DoesNotReturn informs the compiler and analyzers.
Q29
Which attribute is applied at the assembly level?
Answer: Option A
Explanation: AssemblyTitle provides metadata about the assembly.
Q30
Which attribute specifies the version of an assembly?
Answer: Option C
Explanation: AssemblyVersion defines the assembly version.