C# - Attributes Questions and Answers
Practice ModeShowing 10 of 38 questions
Q31
Which attribute allows conditional compilation?
Answer: Option A
Explanation: Conditional includes method calls based on compilation symbols.
Q32
Which attribute is used to define serialization behavior?
Answer: Option A
Explanation: Serializable marks a class as eligible for serialization.
Q33
Which attribute prevents a class from being serialized?
Answer: Option A
Explanation: NonSerialized prevents a field from being serialized.
Q34
Which attribute specifies a default value for a property?
Answer: Option C
Explanation: DefaultValue provides design-time default values.
Q35
Which attribute is used to specify code analysis suppression?
Answer: Option C
Explanation: SuppressMessage disables specific code analysis warnings.
Q36
Which attribute helps control COM visibility?
Answer: Option A
Explanation: ComVisible specifies whether a type is visible to COM.
Q37
Which attribute specifies thread behavior of a method?
Answer: Option B
Explanation: STAThread specifies single-threaded apartment model.
Q38
When are attributes evaluated in C#?
Answer: Option C
Explanation: Attributes are compiled into metadata and accessed at runtime using reflection.