用来标识已过时的类或方法。
示例
using System;
namespace TTest
{
class Program
{
static void Main(string[] args)
{
A a = new A();
B b = new B();
b.OldMethod();
b.NewMethod();
Console.Read();
}
}
[System.Obsolete("use class B")]
class A
{
public void Method() { }
}
class B
{
[System.Obsolete("use NewMethod", true)]
public void OldMethod() { }
public void NewMethod() { }
}
}
编译截图