C# using numbers in an enum

前端 未结 8 1351
迷失自我
迷失自我 2020-11-30 03:02

This is a valid enum

public enum myEnum
{
  a= 1,
  b= 2,
  c= 3,
  d= 4,
  e= 5,
  f= 6,
  g= 7,
  h= 0xff
};

But this is not



        
相关标签:
8条回答
  • 2020-11-30 03:49

    No, there isn't. C# does not allow identifiers to start with a digit.

    Application usability note: In your application you should not display code identifiers to the end-user anyway. Think of translating individual enumeration items into user-friendly displayable texts. Sooner or later you'll have to extend the enum with an item whose identifier won't be in a form displayable to the user.

    UPDATE: Note that the way for attaching displayable texts to enumeration items is being discusses, for example, here.

    0 讨论(0)
  • 2020-11-30 03:49

    No way. A valid identifier (ie a valid enumeration member) cannot start with a digit.

    0 讨论(0)
提交回复
热议问题