C# - Attributes Questions and Answers

Practice Mode
Showing 10 of 38 questions
Q31
Which attribute allows conditional compilation?
  • A Explanation: Conditional includes method calls based on compilation symbols.
  • B IfDefined
  • C DebugOnly
  • D CompileCheck
Answer: Option A
Explanation: Conditional includes method calls based on compilation symbols.
Q32
Which attribute is used to define serialization behavior?
  • A Explanation: Serializable marks a class as eligible for serialization.
  • B Data
  • C Persist
  • D Store
Answer: Option A
Explanation: Serializable marks a class as eligible for serialization.
Q33
Which attribute prevents a class from being serialized?
  • A Explanation: NonSerialized prevents a field from being serialized.
  • B NoSerialize
  • C IgnoreData
  • D SkipSerialize
Answer: Option A
Explanation: NonSerialized prevents a field from being serialized.
Q34
Which attribute specifies a default value for a property?
  • A Default
  • B Value
  • C Explanation: DefaultValue provides design-time default values.
  • D InitValue
Answer: Option C
Explanation: DefaultValue provides design-time default values.
Q35
Which attribute is used to specify code analysis suppression?
  • A Suppress
  • B IgnoreWarning
  • C Explanation: SuppressMessage disables specific code analysis warnings.
  • D CodeIgnore
Answer: Option C
Explanation: SuppressMessage disables specific code analysis warnings.
Q36
Which attribute helps control COM visibility?
  • A Explanation: ComVisible specifies whether a type is visible to COM.
  • B Interop
  • C ComAccess
  • D ExposeCom
Answer: Option A
Explanation: ComVisible specifies whether a type is visible to COM.
Q37
Which attribute specifies thread behavior of a method?
  • A ThreadSafe
  • B Explanation: STAThread specifies single-threaded apartment model.
  • C MultiThread
  • D ThreadMode
Answer: Option B
Explanation: STAThread specifies single-threaded apartment model.
Q38
When are attributes evaluated in C#?
  • A Only at compile time
  • B Only at runtime
  • C Explanation: Attributes are compiled into metadata and accessed at runtime using reflection.
  • D Only during debugging
Answer: Option C
Explanation: Attributes are compiled into metadata and accessed at runtime using reflection.
Questions and Answers for Competitive Exams Various Entrance Test