Skip to content

C# Feature – Attributes

Attributes are classes deriving from System.Attribute that attach metadata to symbols.

C# 1 (2002)

[Obsolete("Use NewMethod")]
void OldMethod() {}
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)]
public sealed class ExampleAttribute(string name) : Attribute
{
public string Name { get; } = name;
}
  • Attribute class names end with Attribute but usage can omit the suffix.
  • Many frameworks read attributes via reflection or source generators.