C# Enum Equals

Description

Enum Equals returns a value indicating whether this instance is equal to a specified object.

Syntax

Enum.Equals has the following syntax.


public override bool Equals(
  Object obj
)

Parameters

Enum.Equals has the following parameters.

  • obj - An object to compare with this instance, or null.

Returns

Enum.Equals method returns true if obj is an enumeration value of the same type and with the same underlying value as this instance; otherwise, false.

Example

The following example illustrates the use of the Equals method.


/*from  w  ww  .  j  a  va 2 s .c  o  m*/
using System;

enum Mammals { Cat, Dog, Horse, Dolphin };
public class EqualsTest {
    public static void Main() {
        Mammals myPet = Mammals.Cat;
        Mammals yourPet = Mammals.Dog;

        Console.WriteLine(myPet.Equals(yourPet));

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version