C# - Attributes Questions and Answers
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
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") >
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? Custom attribute cannot be applied to an assembly. [assembly: Tested("Sachin", testgrade.Good)] [Tested("Virat", testgrade.Excellent)] class customer { /* .... */ } Custom attribute cannot be applied to a method. Custom attribute cannot be applied to a class
- 1 only
- 1, 5
- 2, 3
- 4, 5
13. Attributes can be applied to Method Class Assembly Namespace Enum
- 1 and 2 only
- 1, 2 and 3
- 4 and 5 only
- All of the above