It says here that the possible types for an enum are byte, sbyte, short, ushort, int, uint, long, or ulong.
What if I need a float or a double to define percentage increments such as 1.5 or 2.5 for example? Am I stuck?
As said here:
http://en.csharp-online.net/.NET_Type_Design_Guidelines%E2%80%94Enum_Design
An enum is a structure with a set of static constants. The reason to
follow this guideline is because you will get some additional compiler
and reflection support if you define an enum versus manually defining
a structure with static constants.
Since an enum is a set of constants, why can’t I have float constants ?
Update: it is said here:
http://en.csharp-online.net/.NET_Type_Design_Guidelines%E2%80%94Enum_Design
“Did you know that the CLR supports enums with an underlying type of float or double even though most languages don’t choose to expose it?”
Since I’m only using c# is there a way to do so with some hacks ?
Although the CLR itself supports floating point enums, C# designers chose not to expose this in the language (see http://en.csharp-online.net/.NET_Type_Design_Guidelines%E2%80%94Enum_Design). You can either use constants as in John Saunders’ answer, or you can define an integer enum with multiplied values and then divide them back if/when you need the value.
The use case would be definitely interesting, though. Why do you need/want this?