In the case of using enums, is it better to use:
if (enumInstance.Equals(MyEnum.SomeValue))
or to use
if (enumInstance == MyEnum.SomeValue)
Are their any important considerations using one vs the other?
If the compile-time type of enumInstance
is the enum type, you're fine with ==
.
If the compile-time type of enumInstance
is Enum
, ValueType
or Object
, you need to use Equals
. (You'll get a compile-time error if you try to use ==
in that case.)
Note that your enum currently violates .NET naming conventions - it would normally be MyEnum.Value
.