C# - Attributes Questions and Answers

Take Exam

C# Attributes programming questions and answers help developers understand metadata and reflection in .NET applications. Attributes provide declarative information about program elements, influencing how the runtime behaves. These concepts are often asked in interviews by companies like HCL, Infosys, and TCS to assess deep understanding of advanced C# features. Practicing programming interview questions with answers on attributes helps candidates learn how to create custom attributes, retrieve metadata using reflection, and apply predefined ones like [Obsolete] or [Serializable]. Strengthening this topic ensures you can confidently tackle conceptual and coding questions in software development interviews.

Focus on attributes and modifiers in C programming language. Also try C functions and subroutines and C datatypes
 

C# - Attributes

Showing 10 of 38 questions

31. Which attribute allows conditional compilation?

  • Explanation: Conditional includes method calls based on compilation symbols.
  • IfDefined
  • DebugOnly
  • CompileCheck
Show Answer Report

32. Which attribute is used to define serialization behavior?

  • Explanation: Serializable marks a class as eligible for serialization.
  • Data
  • Persist
  • Store
Show Answer Report

33. Which attribute prevents a class from being serialized?

  • Explanation: NonSerialized prevents a field from being serialized.
  • NoSerialize
  • IgnoreData
  • SkipSerialize
Show Answer Report

34. Which attribute specifies a default value for a property?

  • Default
  • Value
  • Explanation: DefaultValue provides design-time default values.
  • InitValue
Show Answer Report

35. Which attribute is used to specify code analysis suppression?

  • Suppress
  • IgnoreWarning
  • Explanation: SuppressMessage disables specific code analysis warnings.
  • CodeIgnore
Show Answer Report

36. Which attribute helps control COM visibility?

  • Explanation: ComVisible specifies whether a type is visible to COM.
  • Interop
  • ComAccess
  • ExposeCom
Show Answer Report

37. Which attribute specifies thread behavior of a method?

  • ThreadSafe
  • Explanation: STAThread specifies single-threaded apartment model.
  • MultiThread
  • ThreadMode
Show Answer Report

38. When are attributes evaluated in C#?

  • Only at compile time
  • Only at runtime
  • Explanation: Attributes are compiled into metadata and accessed at runtime using reflection.
  • Only during debugging
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test