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?
C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...
What is C? C is a general-purpose programming language created by Dennis Ritchie at the Bell Laboratories in 1972. It is a very popular language, despite being old. C is strongly associated with UNIX, as it was developed to write the UNIX operating system.
Compared to other languages—like Java, PHP, or C#—C is a relatively simple language to learn for anyone just starting to learn computer programming because of its limited number of keywords.
History: The name C is derived from an earlier programming language called BCPL (Basic Combined Programming Language). BCPL had another language based on it called B: the first letter in BCPL.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With