Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enum deprecated c#

Tags:

c#

.net

enums

I have a deprecated (Obsolete) function which returns an enum, and I have a new function which returns a List of enums.

One of the enum values is used only in the deprecated function, so is it possible to set an enum member as obsolete (because it can't be in the List)?

like image 878
JohnJohnGa Avatar asked Dec 21 '11 10:12

JohnJohnGa


People also ask

Can enum values be changed in C?

You can change default values of enum elements during declaration (if necessary).

Was declared deprecated C++?

The deprecated declaration lets you specify particular forms of function overloads as deprecated, whereas the pragma form applies to all overloaded forms of a function name. The deprecated declaration lets you specify a message that will display at compile time. The text of the message can be from a macro.

What does deprecated mean in C++?

Deprecated attribute in C++14 with Examples Deprecated means the use of the name or entity declared with this attribute is allowed but discouraged for some reason.

What is enum in Android Studio?

Enum in java is a data type that contains fixed set of constants. When we required predefined set of values which represents some kind of data, we use ENUM. We always use Enums when a variable can only take one out of a small set of possible values.


2 Answers

Sure, you can:

public enum EE
{
    A,

    [Obsolete]
    B
}
like image 183
Kirill Polishchuk Avatar answered Oct 20 '22 05:10

Kirill Polishchuk


Actually, it is possible to generate either compiler warnings or compiler errors.

public enum TestEnum
{
    A,
    [Obsolete("Not in use anymore")]
    B,
    [Obsolete("Not in use anymore", true)]
    C,
}

public class Class1
{
    public void TestMethod()
    {
        TestEnum t1 = TestEnum.A; //Works just fine.
        TestEnum t2 = TestEnum.B; //Will still compile, but generates a warning.
        TestEnum t3 = TestEnum.C; //Will no longer compile. 
    }
}

This will work wherever you use an [Obsolete] attribute.

like image 39
Arno Peters Avatar answered Oct 20 '22 05:10

Arno Peters