C# - Attributes Questions and Answers

Practice Mode
Showing 10 of 38 questions
Q21
Which attribute indicates that a class should not be inherited?
  • A NonInheritable
  • B Final
  • C Explanation: sealed prevents a class from being inherited, though it is not an attribute.
  • D Obsolete
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?
  • A Deprecated
  • B Old
  • C Explanation: Obsolete warns that a member should no longer be used.
  • D Legacy
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?
  • A Warning is ignored
  • B Program fails at runtime
  • C Explanation: Setting error = true causes a compilation error when used.
  • D Attribute is skipped
Answer: Option C
Explanation: Setting error = true causes a compilation error when used.
Q24
Which attribute hides a public member from IntelliSense?
  • A Hidden
  • B Explanation: EditorBrowsable controls visibility in IntelliSense.
  • C NonBrowsable
  • D Ignore
Answer: Option B
Explanation: EditorBrowsable controls visibility in IntelliSense.
Q25
Which attribute specifies a method that should run before a test?
  • A PreTest
  • B TestInit
  • C Explanation: TestInitialize is used in unit testing frameworks.
  • D Setup
Answer: Option C
Explanation: TestInitialize is used in unit testing frameworks.
Q26
Which reflection class is commonly used to read attributes at runtime?
  • A AttributeReader
  • B Explanation: The Type class is used with reflection to retrieve attributes.
  • C AssemblyInfo
  • D MetaData
Answer: Option B
Explanation: The Type class is used with reflection to retrieve attributes.
Q27
Which method retrieves attributes applied to a program element?
  • A GetAttribute()
  • B ReadAttributes()
  • C Explanation: GetCustomAttributes() is used to obtain attribute instances.
  • D FetchAttributes()
Answer: Option C
Explanation: GetCustomAttributes() is used to obtain attribute instances.
Q28
Which attribute indicates a method does not return a value?
  • A Void
  • B NoReturn
  • C Explanation: DoesNotReturn informs the compiler and analyzers.
  • D Returnless
Answer: Option C
Explanation: DoesNotReturn informs the compiler and analyzers.
Q29
Which attribute is applied at the assembly level?
  • A Explanation: AssemblyTitle provides metadata about the assembly.
  • B AssemblyUsage
  • C AssemblyInfo
  • D AssemblyScope
Answer: Option A
Explanation: AssemblyTitle provides metadata about the assembly.
Q30
Which attribute specifies the version of an assembly?
  • A AssemblyBuild
  • B AssemblyInfo
  • C Explanation: AssemblyVersion defines the assembly version.
  • D AssemblyLevel
Answer: Option C
Explanation: AssemblyVersion defines the assembly version.
Questions and Answers for Competitive Exams Various Entrance Test