C# Feature – Attributes
Overview
Section titled “Overview”Attributes are classes deriving from System.Attribute that attach metadata to symbols.
Introduced In
Section titled “Introduced In”C# 1 (2002)
Example
Section titled “Example”[Obsolete("Use NewMethod")]void OldMethod() {}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]public sealed class ExampleAttribute(string name) : Attribute{ public string Name { get; } = name;}
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Attribute class names end with Attribute but usage can omit the suffix.
- Many frameworks read attributes via reflection or source generators.