X

C# tip – Marking method or class as Obsolete/Deprecated

dotnet C#

Obsolete or Deprecated?

How do you mark a class or method as deprecated/obsolete?

By using the Obsolete attribute


[Obsolete]
public class Person { }

[Obsolete("Class is obsolete, use PersonImpl")]
public class Person { }

//compilation to fail methods calling this code
[Obsolete("Class is obsolete, use PersonImpl", true)]
public class Person { }

[Obsolete("Method is obsolete, use SomeMethod2", true)]
public void SomeMethod() { }
Categories: .NET C#
Taswar Bhatti:
Related Post