farseer <fa*****@optonline.net> wrote:
if an enum requires boxing often, i'd assume constants would win on
performance, is that true?
Further, it appears that if you need to pass enum values to functions
that accept only uint, int or byte (therefore, you also must unbox and
cast the enums to the type it "inherits" from) quite often, then
constants may be a better choice if performance is an issue.
Are these assumptions correct?
Firstly, as Mattias says, there's no more boxing involved with enums
than with value-type constants. Casting an enum to an int doesn't box
or unbox it, for instance.
Secondly, even if there were some slight performance improvement from
using a constant compared with an enum, I'd *prove* that it was
actually significant in the system before moving to a less strongly
type for the sake of performance.
It's quite possible for performance to an issue, but for it still not
to be worth micro-optimising.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too