How to mark a class as Deprecated?


Question

Possible Duplicate:
How do I mark a method as Obsolete/Deprecated? - C#

How do you mark a class as deprecated? I do not want to use a class any more in my project, but do not want to delete it before a period of 2 weeks.

1
210
5/23/2017 11:47:27 AM

Accepted Answer

You need to use the attribute [Obsolete].

This is an example:

[Obsolete("Not used any more", true)]
public class MyDeprecatedClass
{
    //...
}

You do not have use parameters, they are optional (overloaded method). The first parameter is for the reason and the last one is to mark an Error in compile time instead of a warning.

377
10/5/2018 12:57:46 PM

As per Doak's answer, but the attribute's second parameter should be set to false if you want the code to compile:

[Obsolete("Not used any more", false)]
public class MyDeprecatedClass
{
        //...
}

This will just throw warnings.


Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon