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.
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.
Enum Values The first member of an enum will be 0, and the value of each successive enum member is increased by 1.
#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.
Variable names cannot start with number.
I know of no convention, but how about
public enum EthernetLinkSpeed {
Link10BaseT, Link1000BaseT, LinkDisconnected
}
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.
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
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With