Practice mode C#

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

Explanation

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.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.