Marks a program entity that should not be used.
[Obsolete(
message
)]
[Obsolete(
message,
iserror
)]
Parameters
- message
- A string; ideally, a human-readable explanation of why the item is obsolete and what to use instead.
- iserror
- A bool; if true, the compiler should treat the use of the item as an error. Default value is false (compiler generates a warning).
Applies To
Any declaration that allows attributes.
Remarks
The Obsolete attribute is a single-use attribute. Obsolete is an alias for System.ObsoleteAttribute.
When an entity marked Obsolete is used in a program, the compiler issues either an error or a warning (depending on iserror) and prints out message.
Example
// cs_attribute_obsolete.cs
// CS0619 expected
using System;
public class MyClass
{
[Obsolete("Don't use OldWay; use NewWay instead", true)]
static void OldWay( ) { Console.WriteLine("Silly me!"); }
static void NewWay( ) { Console.WriteLine("D'oh!"); }
public static void Main( )
{
OldWay( );
}
} See Also
C# Attributes