Back to course

Attributes in C#

C# Zero to Hero: Comprehensive Programming Masterclass

Using Attributes

Attributes provide a powerful method of associating metadata, or declarative information, with code.

Common Attributes

  • [Serializable]: Allows a class to be serialized.
  • [Obsolete]: Marks a method as outdated.
  • [Required]: Used in web apps for data validation.

csharp [Obsolete("Use NewMethod instead")] public void OldMethod() { ... }