Two enums have some elements in common, why does this produce an error?

后端 未结 8 725
难免孤独
难免孤独 2021-01-01 09:17

I have two enums in my code:

enum Month {January, February, March, April, May, June, July,
        August, September, October, November, December};
enum Shor         


        
8条回答
  •  一向
    一向 (楼主)
    2021-01-01 09:30

    I suggest you merge the two:

    enum Month {
      Jan, January=Jan, Feb, February=Feb, Mar, March=Mar, 
      Apr, April=Apr,   May,               Jun, June=Jun, 
      Jul, July=Jul,    Aug, August=Aug,   Sep, September=Sep, 
      Oct, October=Oct, Nov, November=Nov, Dec, December=Dec};
    

    Which will have exactly the same effect, and is more convenient.

    If you want January to have the value 1, instead of 0, add this:

    enum Month {
      Jan=1, January=Jan, Feb, February=Feb, ....
    

提交回复
热议问题