本文整理汇总了VB.NET中System.Enum.Equals方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enum.Equals方法的具体用法?VB.NET Enum.Equals怎么用?VB.NET Enum.Equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Enum
的用法示例。
在下文中一共展示了Enum.Equals方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: EqualsTest
Public Class EqualsTest
Enum Colors
Red
Green
Blue
Yellow
End Enum
Enum Mammals
Cat
Dog
Horse
Dolphin
End Enum
Public Shared Sub Main()
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
Console.WriteLine("My favorite animal is a {0}", myPet)
Console.WriteLine("Your favorite animal is a {0}", yourPet)
If myPet.Equals(yourPet) Then output = "Yes" Else output = "No"
Console.WriteLine("Do we like the same animal? {0}", output)
Console.WriteLine()
Console.WriteLine("My favorite color is {0}", myColor)
Console.WriteLine("Your favorite color is {0}", yourColor)
If myColor.Equals(yourColor) Then output = "Yes" Else output = "No"
Console.WriteLine("Do we like the same color? {0}", output)
Console.WriteLine()
Console.WriteLine("The value of my color ({0}) is {1}", myColor, [Enum].Format(GetType(Colors), myColor, "d"))
Console.WriteLine("The value of my pet (a {0}) is {1}", myPet, [Enum].Format(GetType(Mammals), myPet, "d"))
Console.WriteLine("Even though they have the same value, are they equal? {0}",
If(myColor.Equals(myPet), "Yes", "No"))
End Sub
End Class
输出:
My favorite animal is a Cat Your favorite animal is a Dog Do we like the same animal? No My favorite color is Red Your favorite color is Red Do we like the same color? Yes The value of my color (Red) is 0 The value of my pet (a Cat) is 0 Even though they have the same value, are they equal? No
示例2: Example
Public Enum SledDog As Integer
Unknown=0
AlaskanMalamute=1
Malamute=1
Husky=2
SiberianHusky=2
End Enum
Public Enum WorkDog As Integer
Unknown=0
Newfoundland=1
GreatPyrennes=2
End Enum
Module Example
Public Sub Main()
Dim dog1 As SledDog = SledDog.Malamute
Dim dog2 As SledDog = SledDog.AlaskanMalamute
Dim dog3 As WorkDog = WorkDog.Newfoundland
Console.WriteLine("{0:F} ({0:D}) = {1:F} ({1:D}): {2}",
dog1, dog2, dog1.Equals(dog2))
Console.WriteLine("{0:F} ({0:D}) = {1:F} ({1:D}): {2}",
dog1, dog3, dog1.Equals(dog3))
End Sub
End Module
输出:
Malamute (1) = Malamute (1): True Malamute (1) = Newfoundland (1): False