Enum::Equals Method
Returns a value indicating whether this instance is equal to a specified object.
Assembly: mscorlib (in mscorlib.dll)
Parameters
- obj
- Type: System::Object
An object to compare with this instance, or nullptr.
Return Value
Type: System::Booleantrue if obj is an Enum with the same underlying type and value as this instance; otherwise, false.
The following example illustrates the use of Equals in the context of Enum.
using namespace System; enum class Colors { Red, Green, Blue, Yellow }; enum class Mammals { Cat, Dog, Horse, Dolphin }; int main() { Mammals myPet = Mammals::Cat; Colors myColor = Colors::Red; Mammals yourPet = Mammals::Dog; Colors yourColor = Colors::Red; Console::WriteLine( "My favorite animal is a {0}", myPet ); Console::WriteLine( "Your favorite animal is a {0}", yourPet ); Console::WriteLine( "Do we like the same animal? {0}", myPet.Equals( yourPet ) ? (String^)"Yes" : "No" ); Console::WriteLine(); Console::WriteLine( "My favorite color is {0}", myColor ); Console::WriteLine( "Your favorite color is {0}", yourColor ); Console::WriteLine( "Do we like the same color? {0}", myColor.Equals( yourColor ) ? (String^)"Yes" : "No" ); Console::WriteLine(); Console::WriteLine( "The value of my color ({0}) is {1}", myColor, Enum::Format( Colors::typeid, myColor, "d" ) ); Console::WriteLine( "The value of my pet (a {0}) is {1}", myPet, Enum::Format( Mammals::typeid, myPet, "d" ) ); Console::WriteLine( "Even though they have the same value, are they equal? {0}", myColor.Equals( myPet ) ? (String^)"Yes" : "No" ); }
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.