What is the purpose of attributes such as in C#?
Correct answer D. To attach declarative metadata to code elements that tools or reflection can read
Attributes add metadata to assemblies, types, methods, properties and parameters. The compiler, frameworks and your own code can read them through reflection. [Obsolete] makes the compiler warn when a member is used, while serialisers and test frameworks rely on attributes like [JsonPropertyName] or [Fact]. Custom attributes are classes deriving from System.Attribute.
Answer checked How we write and check questions
Discussion