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 13 questions

1. The [Serializable()] attribute gets inspected at

  • Compile-time
  • Run-time
  • Design-time
  • Linking-time
Show Answer Report

2. Which of the following are correct ways to specify the targets for a custom attribute?

  • By applying AttributeUsage to the custom attribute's class definition.
  • By applying UsageAttribute to the custom attribute's class definition.
  • Once an attribute is declared it applies to all the targets.
  • By applying AttributeUsageAttribute to the custom attribute's class definition.
Show Answer Report

3. Which of the following are correct ways to pass a parameter to an attribute?     By value     By reference     By address     By position     By name

  • 1, 2
  • 1, 2, 3
  • 4, 5
  • All of the above
Show Answer Report

4. Which of the following statements are correct about inspecting an attribute in C#.NET?     An attribute can be inspected at link-time.     An attribute can be inspected at compile-time.     An attribute can be inspected at run-time.     An attribute can be inspected at design-time.

  • 1, 2
  • 3, 4
  • 1, 3, 4
  • All of the above
Show Answer Report

5. Which of the following statements are correct about Attributes used in C#.NET?

  • If there is a custom attribute BugFixAttribute then the compiler will look ONLY for the BugFix attribute in the code that uses this attribute.
  • To create a custom attribute we need to create a custom attribute structure and derive it from System.Attribute.
  • To create a custom attribute we need to create a class and implement IAttribute interface in it.
  • If a BugFixAttribute is to receive three parameters then the BugFixAttribute class should implement a zero-argument constructor.
Show Answer Report

6. Which of the following statements are correct about Attributes in C#.NET?     On compiling a C#.NET program the attibutes applied are recorded in the metadata of the assembly.     On compilation all the attribute's tags are deleted from the program.     It is not possible to create custom attributes..     The attributes applied can be read from an assembly using Reflection class.     An attribute can have parameters.

  • 1 and 2 only
  • 2 and 4 only
  • 1, 4 and 5 only
  • All of the above
Show Answer Report

7. Which of the following correctly describes the contents of the filename AssemblyInfo.cs?

  • It contains method-level attributes.
  • It contains class-level attributes.
  • It contains assembly-level attributes.
  • It contains structure-level attributes.
Show Answer Report

8. It possible to create a custom attribute that can be applied only to specific programming element(s) like ____ .

  • Classes
  • Methods
  • Classes and Methods
  • Classes, Methods and Member-Variables
Show Answer Report

9. Which of the following CANNOT be a target for a custom attribute?

  • Enum
  • Event
  • Delegate
  • Interface
Show Answer Report

10. Once applied which of the following CANNOT inspect the applied attribute?

  • CLR
  • Linker
  • ASP.NET Runtime
  • Visual Studio.NET
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test