By default, C# enums are stored as integers. I'd like to make it a short instead. Is there a way to do this?
+7
A:
sure, this can be done, but it has to be an integral type ( byte, short, int, etc.) except char...
enum myEnum : short
{
FirstValue = 0,
};
here is the MSDN docs
Muad'Dib
2010-09-03 04:09:00
+1 for beating @RPM1984 by half a minute... lol
rockinthesixstring
2010-09-03 04:10:39
I blame my office's internet connection. =)
RPM1984
2010-09-03 04:12:24
@rockinthesixstring what else would you expect from the Kwisatz Haderach? ;)
Muad'Dib
2010-09-03 04:14:07
@Maud'Dib - i think char is the exception. i dont think it is allowed. http://msdn.microsoft.com/en-us/library/sbbt4032(VS.80).aspx
InSane
2010-09-03 04:14:15
that is right, any integral type EXCEPT char
Muad'Dib
2010-09-03 04:17:49
Heh thanks, much easier than I thought it'd be! I actually read the doc but didn't scroll down far enough to see the part where uses the inheritance.
Daniel T.
2010-09-03 04:28:58
A:
Sometimes it makes more sense to have String values as enums you can use Attributes and achieve this check this link http://weblogs.asp.net/stefansedich/archive/2008/03/12/enum-with-string-values-in-c.aspx
Kiran Bheemarti
2010-09-03 06:07:01
A:
yes you can create enum like
enum Range : short {Max = 6, Min = 1, Mid = 3};
hemant
2010-09-03 06:14:43