Skip to main content

What is an attribute in C#?

Junior C#
Quick Answer Attributes are metadata tags you attach to classes, methods, or properties using [AttributeName]. Frameworks read them at runtime via reflection to change behavior. Examples: [Required] for validation, [HttpGet] for routing, [Obsolete] to warn callers. You can also write custom attributes.

Answer

An attribute is metadata applied to program elements like classes, methods, or properties.

It helps frameworks control behavior at compile time or runtime.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice