Practice mode C#

A custom attribute class is named ValidatedAttribute. How can it be applied to a method in C#?

Correct answer B. [Validated] or [ValidatedAttribute]

Explanation

By convention attribute class names end in Attribute, and C# lets you omit that suffix when applying them, so [Validated] and [ValidatedAttribute] both refer to the same class. The class must derive from System.Attribute, and AttributeUsage can restrict where it is allowed. @Validated is Java annotation syntax and # introduces preprocessor directives.

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.