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