C#: Why only integral enums?

Posted by JamesBrownIsDead on Stack Overflow See other posts from Stack Overflow or by JamesBrownIsDead
Published on 2010-06-04T00:19:20Z Indexed on 2010/06/15 16:12 UTC
Read the original article Hit count: 217

Filed under:
|
|

I've been writing C# for seven years now, and I keep wondering, why do enums have to be of an integral type? Wouldn't it be nice to do something like:

enum ErrorMessage 
{ 
     NotFound: "Could not find",
     BadRequest: "Malformed request"
}

Is this a language design choice, or are there fundamental incompatibilities on a compiler, CLR, or IL level?

Do other languages have enums with string or complex (i.e. object) types? What languages?

(I'm aware of workarounds; my question is, why are they needed?)

EDIT: "workarounds" = attributes or static classes with consts :)

© Stack Overflow or respective owner

Related posts about c#

Related posts about string