How to indicate that code is obsolete in C# .NET
February 27, 2015 1 Comment
Say you have a class or a class member that you’d like to remove at a later stage. You’ve probably seen compiler warnings or even errors with a message like “abc.efg is obsolete: ‘some message'”.
Let’s see quickly how to achieve it in C#.
The attribute to be aware of is Obsolete. It can decorate both classes, properties and methods. You can attach a useful message to it and make the compiler issue an error instead of the default warning. Let’s see an example:
[Obsolete]
public class CurrentCustomer
{
public void Buy()
{
}
}