Performance comparison between enum and ints calculations

Will there be a difference in speed between

if (myInt == CONST_STATE1)

and

if (myEnum == myENUM.State1)

in c #?

+5
source share
3 answers

In C #, Enumerations are in any case embedded into constants by the compiler, so the advantage is that the code is clear

+11
source

What to consider when using Enums is not to use any operations that require reflection (or use them with caution). For example:

  • myEnumValue.ToString ().
  • Enum.Parse ()
  • Enum.IsDefined ()
  • Enum.GetName ()
  • Enum.GetNames ()

, , . . .

, , / enum, 5% (, API). , , .

, , enum vs. constant , . , , .

+2

, , . . , , .:)

+1

All Articles