Enum addition vs subtraction and casting

前端 未结 3 1234
逝去的感伤
逝去的感伤 2020-12-03 13:33

Why does addition require a cast but subtraction works without a cast? See the code below to understand what I am asking

public enum Stuff
{
    A = 1,
             


        
3条回答
  •  鱼传尺愫
    2020-12-03 14:15

    The problem is that "+" in this context is not like a plus between the values of enumeration. It is important to understand that + is operator and there are no rules defined how to apply it to operands ( Stuff.A and Stuff.B)

提交回复
热议问题