Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a naming convention for enum values that have a leading digit?

Tags:

c#

enums

I have a c# enumeration that looks like this:

public enum EthernetLinkSpeed {

    [Description("10BASE-T")]
    _10BaseT,

    [Description("100BASE-T")]
    _100BaseT,

    [Description("1000BASE-T")]
    _1000BaseT,

    [Description("Disconnected")]
    Disconnected
}

I added a leading underscore to each value to make the compiler happy.

Is there a standard naming convention for enumerations like this? The underscore I've used doesn't seem like the best choice.

like image 311
user158485 Avatar asked Sep 08 '09 16:09

user158485


People also ask

How should enums be named?

Enums are types, so they should be named using UpperCamelCase like classes. The enum values are constants, so they should be named using lowerCamelCase like constants, or ALL_CAPS if your code uses that legacy naming style.

What number do enums start with?

Enum Values The first member of an enum will be 0, and the value of each successive enum member is increased by 1.

Should enum be capitalized in C?

#define constants should be in all CAPS. Function, typedef, and variable names, as well as struct, union, and enum tag names should be in lower case.

Can enum start with number C#?

Variable names cannot start with number.


3 Answers

I know of no convention, but how about

public enum EthernetLinkSpeed {
 Link10BaseT, Link1000BaseT, LinkDisconnected
}
like image 175
CVertex Avatar answered Sep 28 '22 00:09

CVertex


I just look for something more descriptive in this case. For instance, since you have a "Disconnected" enum value, I would use something like:

public enum EthernetLinkSpeed {
    Connected10BaseT,
    Connected100BaseT,
    Connected1000BaseT,
    Disconnected
}

Since these are compile-time only, there's no damage in having them as long you like, even if making them long just means making them descriptive enough to pass the compiler's naming rules.

like image 36
JoshJordan Avatar answered Sep 28 '22 00:09

JoshJordan


Not a direct answer, but the built-in NetworkInterfaceType enum includes the following values:

Ethernet, Ethernet3Megabit, FastEthernetT, FastEthernetFx, GigabitEthernet

It's a bit ugly for my liking, but I might consider using an Ethernet prefix for your enum:

public enum EthernetLinkSpeed
{
    [Description("10BASE-T")]
    Ethernet10BaseT,

    [Description("100BASE-T")]
    Ethernet100BaseT,

    [Description("1000BASE-T")]
    Ethernet1000BaseT,

    [Description("Disconnected")]
    Disconnected
}
like image 41
LukeH Avatar answered Sep 28 '22 00:09

LukeH