When declaring an enum, should you force the type to byte for under 256 entities?

后端 未结 7 1608
夕颜
夕颜 2020-12-13 08:51

If you have an enum in your application and you only have a few items, should you force the underlying type to be the smallest possible type?

    enum smalle         


        
7条回答
  •  遥遥无期
    2020-12-13 09:22

    In .Net core, if you call Enum.IsDefined to check if the passing in value existed in an enum, you should ensure types are the same.

    ArgumentException: Enum underlying type and the object must be same type or object must be a String.

提交回复
热议问题