Enum.Equals Method
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
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 Nothing.
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.
Public Class Example Enum Colors Red Green Blue Yellow End Enum 'Colors Enum Mammals Cat Dog Horse Dolphin End Enum 'Mammals Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) Dim myPet As Mammals = Mammals.Cat Dim myColor As Colors = Colors.Red Dim yourPet As Mammals = Mammals.Dog Dim yourColor As Colors = Colors.Red Dim output As String outputBlock.Text += String.Format("My favorite animal is a {0}", myPet) & vbCrLf outputBlock.Text += String.Format("Your favorite animal is a {0}", yourPet) & vbCrLf If myPet.Equals(yourPet) Then output = "Yes" Else output = "No" outputBlock.Text += String.Format("Do we like the same animal? {0}", output) & vbCrLf outputBlock.Text &= vbCrLf outputBlock.Text += String.Format("My favorite color is {0}", myColor) & vbCrLf outputBlock.Text += String.Format("Your favorite color is {0}", yourColor) & vbCrLf If myColor.Equals(yourColor) Then output = "Yes" Else output = "No" outputBlock.Text += String.Format("Do we like the same color? {0}", output) & vbCrLf outputBlock.Text &= vbCrLf outputBlock.Text += String.Format("The value of my color ({0}) is {1}", myColor, myColor.ToString("d")) & vbCrLf outputBlock.Text += String.Format("The value of my pet (a {0}) is {1}", myPet, myPet.ToString("d")) & vbCrLf If myColor.Equals(myPet) Then output = "Yes" Else output = "No" outputBlock.Text += String.Format("Even though they have the same value, are they equal? {0}", output) & vbCrLf End Sub 'Main End Class 'EqualsTest
Show: