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

11. Which of the following is the correct way to apply an attribute to an Assembly?

  • [ AssemblyDescription("DCube Component Library") ]
  • [ assembly : AssemblyDescription("DCube Component Library") ]
  • [ Assemblylnfo : AssemblyDescription("DCube Component Library") ]
  • < Assembly: AssemblyDescription("DCube Component Library") >
Show Answer Report

12. Which of the following is the correct way of applying the custom attribute called Tested which receives two-arguments - name of the tester and the testgrade? &nbsp;&nbsp;&nbsp; Custom attribute cannot be applied to an assembly. &nbsp;&nbsp;&nbsp; [assembly: Tested(&quot;Sachin&quot;, testgrade.Good)] &nbsp;&nbsp;&nbsp; [Tested(&quot;Virat&quot;, testgrade.Excellent)] &nbsp;&nbsp;&nbsp; class customer { /* .... */ } &nbsp;&nbsp;&nbsp; Custom attribute cannot be applied to a method. &nbsp;&nbsp;&nbsp; Custom attribute cannot be applied to a class

  • 1 only
  • 1, 5
  • 2, 3
  • 4, 5
Show Answer Report

13. Attributes can be applied to &nbsp;&nbsp;&nbsp; Method &nbsp;&nbsp;&nbsp; Class &nbsp;&nbsp;&nbsp; Assembly &nbsp;&nbsp;&nbsp; Namespace &nbsp;&nbsp;&nbsp; Enum

  • 1 and 2 only
  • 1, 2 and 3
  • 4 and 5 only
  • All of the above
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test