Operator “>” cannot be applied to type 'ulong' and 'int'

后端 未结 3 1268
时光说笑
时光说笑 2020-12-03 20:33

I\'m curious to know why the C# compiler only gives me an error message for the second if statement.

enum Permissions : ulong
{
    ViewListItems = 1L,
}

pu         


        
3条回答
  •  春和景丽
    2020-12-03 21:34

    It's not the CLR giving this error message it's the compiler.

    In your first example the compiler treats 32 as ulong (or a type that's implicitly convertible to ulong eg uint) whereas in your second example you've explicitly declared the type as an int. There is no overload of the > operator that accepts an ulong and an int and hence you get a compiler error.

提交回复
热议问题