本文整理汇总了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.