本文整理匯總了VB.NET中System.Enum.IsDefined方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Enum.IsDefined方法的具體用法?VB.NET Enum.IsDefined怎麽用?VB.NET Enum.IsDefined使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Enum
的用法示例。
在下文中一共展示了Enum.IsDefined方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
<Flags> Public Enum PetType As Integer
None = 0
Dog = 1
Cat = 2
Rodent = 4
Bird = 8
Reptile = 16
Other = 32
End Enum
Module Example
Public Sub Main()
Dim value As Object
' Call IsDefined with underlying integral value of member.
value = 1
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
' Call IsDefined with invalid underlying integral value.
value = 64
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
' Call IsDefined with string containing member name.
value = "Rodent"
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
' Call IsDefined with a variable of type PetType.
value = PetType.Dog
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
value = PetType.Dog Or PetType.Cat
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
' Call IsDefined with uppercase member name.
value = "None"
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
value = "NONE"
Console.WriteLine("{0}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
' Call IsDefined with combined value
value = PetType.Dog Or PetType.Bird
Console.WriteLine("{0:D}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
value = value.ToString()
Console.WriteLine("{0:D}: {1}", value, [Enum].IsDefined(GetType(PetType), value))
End Sub
End Module
輸出:
1: True 64: False Rodent: True Dog: True Dog, Cat: False None: True NONE: False 9: False Dog, Bird: False
示例2: Example
<Flags> Public Enum Pets As Integer
None = 0
Dog = 1
Cat = 2
Bird = 4
Rodent = 8
Other = 16
End Enum
Module Example
Public Sub Main()
Dim value As Pets = Pets.Dog Or Pets.Cat
Console.WriteLine("{0:D} Exists: {1}",
value, Pets.IsDefined(GetType(Pets), value))
Dim name As String = value.ToString()
Console.WriteLine("{0} Exists: {1}",
name, Pets.IsDefined(GetType(Pets), name))
End Sub
End Module
輸出:
3 Exists: False Dog, Cat Exists: False