Are all Enum enumerations constants? Do they get converted to their value at compile-time, or at run-time?
Asked
Active
Viewed 2,807 times
13
-
Can't imagine why anyone would vote down this question. – AnthonyWJones Jan 01 '09 at 22:24
-
Maybe because (s)he thought that anyone could answer this question with Google and should try that first. I personally haven't yet come to a conclusion where to draw the line, but IMHO there should be a line. – Jan 01 '09 at 22:37
-
Google's powered by sites like this so easy questions like this are fine by me. I'd much prefer these to all the silly poll questions. – Michael Haren Jan 01 '09 at 23:49
-
Sure, Google will index this answer too. But sometimes I wish there was a little less I'm-too-lazy-to-Google-myself noise in all the newsgroups, which would leave us more time to deal with the interesting questions. Note: I'm not saying that this question is noise, but others might have thought so. – Jan 02 '09 at 00:28
-
True--I can't argue with you there. – Michael Haren Jan 02 '09 at 00:43
-
Andreas, the key takeaway is everybody's "line" is drawn in a different position. – icelava Jan 02 '09 at 02:06
-
1I've been bitten by this! http://stackoverflow.com/questions/194484/whats-the-strangest-corner-case-youve-seen-in-c-or-net/311831#311831 – Benjol May 19 '09 at 08:35
-
1Sometimes questions like this can bring out interesting comments that are tangental to the straightforward main question. – LegendLength Jun 16 '09 at 12:46
2 Answers
17
They are constant. Yes, compile time.
Reference: http://msdn.microsoft.com/en-us/library/sbbt4032.aspx
From the intro:
The enum keyword is used to declare an enumeration, a distinct type that consists of a set of named constants called the enumerator list.
Under "Robust Programming":
Just as with any constant, all references to the individual values of an enum are converted to numeric literals at compile time. This can create potential versioning issues as described in Constants (C# Programming Guide).

Michael Haren
- 105,752
- 40
- 168
- 205
7
Enum values are constants, they cannot change.
Their values are fixed at compile time.

AnthonyWJones
- 187,081
- 35
- 232
- 306