Example

using System;

namespace Samples
{
  public class ObsoleteAttributeSample
  {
    [ObsoleteAttribute("Use NewMethod")]
    public static void OldMethod()
    {
      Console.WriteLine("Hi world!");
    }
    public static void NewMethod()
    {
      Console.WriteLine("Hello world!");
    }
    public static void Main()
    {
      OldMethod();
    }
  }
}
An example compile-time result is
 Microsoft (R) Program Maintenance Utility Version 7.00.9466 Copyright (C) Microsoft Corporation. All rights reserved. csc /debug ObsoleteAttribute.cs Microsoft (R) Visual C# .NET Compiler version 7.00.9466 for Microsoft (R) .NET Framework version 1.0.3705 Copyright (C) Microsoft Corporation 2001. All rights reserved. ObsoleteAttribute.cs(18,7): warning CS0618: 'Samples.ObsoleteAttributeSample.OldMethod()' is obsolete: ...

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.