Given the following enum,
enum ExampleOptions
{
OptionA,
OptionB
}
Is there any real difference between these two statements?
ExampleOptions option = ExampleOptions.OptionA;
bool equals1 = option == ExampleOptions.OptionA; // true
bool equals2 = option is ExampleOptions.OptionA; // true
As far as I can see, the only difference between using == and is is mainly that is expects a constant operand (thus, operation order matters).
I used to use the
==operator just because I wanted to avoid ugly statements such as
!(option is ExampleOptions.OptionA).
But, after C#9 was released and theis notoperator added; I findis/is nota cleaner and more verbose way to write this kind of statements.
Is there any hidden consequence of deciding which operator to use?