本文整理匯總了VB.NET中System.Enum.HasFlag方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Enum.HasFlag方法的具體用法?VB.NET Enum.HasFlag怎麽用?VB.NET Enum.HasFlag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Enum
的用法示例。
在下文中一共展示了Enum.HasFlag方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Example
<Flags> Public Enum DinnerItems As Integer
None = 0
Entree = 1
Appetizer = 2
Side = 4
Dessert = 8
Beverage = 16
BarBeverage = 32
End Enum
Module Example
Public Sub Main()
Dim myOrder As DinnerItems = DinnerItems.Appetizer Or DinnerItems.Entree Or
DinnerItems.Beverage Or DinnerItems.Dessert
Dim flagValue As DinnerItems = DinnerItems.Entree Or DinnerItems.Beverage
Console.WriteLine("{0} includes {1}: {2}",
myOrder, flagValue, myOrder.HasFlag(flagValue))
End Sub
End Module
輸出:
Entree, Appetizer, Dessert, Beverage includes Entree, Beverage: True
示例2: Example
<Flags> Public Enum Pets
None = 0
Dog = 1
Cat = 2
Bird = 4
Rabbit = 8
Other = 16
End Enum
Module Example
Public Sub Main()
Dim petsInFamilies() As Pets = { Pets.None, Pets.Dog Or Pets.Cat, Pets.Dog }
Dim familiesWithoutPets As Integer
Dim familiesWithDog As Integer
For Each petsInFamily In petsInFamilies
' Count the number of families that have no pets.
If petsInFamily.Equals(Pets.None) Then
familiesWithoutPets += 1
' Of families that have pets, count the number of families with a dog.
Else If petsInFamily.HasFlag(Pets.Dog) Then
familiesWithDog += 1
End If
Next
Console.WriteLine("{0} of {1} families in the sample have no pets.",
familiesWithoutPets, petsInFamilies.Length)
Console.WriteLine("{0} of {1} families in the sample have a dog.",
familiesWithDog, petsInFamilies.Length)
End Sub
End Module
輸出:
1 of 3 families in the sample have no pets. 2 of 3 families in the sample have a dog.