本文整理匯總了VB.NET中System.Enum.GetValues方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET Enum.GetValues方法的具體用法?VB.NET Enum.GetValues怎麽用?VB.NET Enum.GetValues使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Enum
的用法示例。
在下文中一共展示了Enum.GetValues方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: GetValuesTest
Public Class GetValuesTest
Enum Colors
Red
Green
Blue
Yellow
End Enum 'Colors
Enum Styles
Plaid = 0
Striped = 23
Tartan = 65
Corduroy = 78
End Enum 'Styles
Public Shared Sub Main()
Console.WriteLine("The values of the Colors Enum are:")
Dim i As Integer
For Each i In [Enum].GetValues(GetType(Colors))
Console.WriteLine(i)
Next
Console.WriteLine()
Console.WriteLine("The values of the Styles Enum are:")
For Each i In [Enum].GetValues(GetType(Styles))
Console.WriteLine(i)
Next
End Sub
End Class
輸出:
The values of the Colors Enum are: 0 1 2 3 The values of the Styles Enum are: 0 23 65 78
示例2: Example
Public Enum SignMagnitude As Integer
Negative = -1
Zero = 0
Positive = 1
End Enum
Module Example
Public Sub Main()
Dim values() As Integer = CType([Enum].GetValues(GetType(SignMagnitude)), Integer())
For Each value In values
Console.WriteLine("{0,3} 0x{0:X8} {1}",
value, CType(value, SignMagnitude).ToString())
Next
End Sub
End Module
輸出:
0 0x00000000 Zero 1 0x00000001 Positive -1 0xFFFFFFFF Negative
示例3:
<Flags> Public Enum Pets As Integer
None = 0
Dog = 1
Cat = 2
Rodent = 4
Bird = 8
Fish = 16
Reptile = 32
Other = 64
End Enum
示例4: Main
' 導入命名空間
Imports System.Reflection
Module Example
Public Sub Main()
Dim assem As Assembly = Assembly.ReflectionOnlyLoadFrom(".\Enumerations.dll")
Dim typ As Type = assem.GetType("Pets")
Dim fields As FieldInfo() = typ.GetFields
For Each field In fields
If field.Name.Equals("value__") Then Continue For
Console.WriteLine("{0,-9} {1}", field.Name + ":",
field.GetRawConstantValue())
Next
End Sub
End Module
輸出:
None: 0 Dog: 1 Cat: 2 Rodent: 4 Bird: 8 Fish: 16 Reptile: 32 Other: 64