开发者

How do I change the type of an enum?

By default, C# enums are stored as intege开发者_开发知识库rs. I'd like to make it a short instead. Is there a way to do this?


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


Like this:

enum MyEnum : short
{
  ...
}


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


yes you can create enum like

enum Range : short {Max = 6, Min = 1, Mid = 3};
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜