Just an academical question:
Is it possible to avoid int casting when comparing Enum to int?
int i = 0;
if(i == (int)MyEnum.Whatever)
{
}
I would like to overload == operator in such a manner:
public static MyEnum operator ==(int lhs, MyEnum rhs)
{}
Thanks for reading 😉
You can’t. See this similar question. As suggested in that question, you could define an extension method to do the comparison, in order to get rid of the repeated casts.