本文整理汇总了VB.NET中System.Enum.GetNames方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Enum.GetNames方法的具体用法?VB.NET Enum.GetNames怎么用?VB.NET Enum.GetNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Enum
的用法示例。
在下文中一共展示了Enum.GetNames方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: GetNamesTest
Public Class GetNamesTest
Enum Colors
Red
Green
Blue
Yellow
End Enum
Enum Styles
Plaid
Striped
Tartan
Corduroy
End Enum
Public Shared Sub Main()
Console.WriteLine("The members of the Colors enum are:")
For Each s In [Enum].GetNames(GetType(Colors))
Console.WriteLine(s)
Next
Console.WriteLine()
Console.WriteLine("The members of the Styles enum are:")
For Each s In [Enum].GetNames(GetType(Styles))
Console.WriteLine(s)
Next
End Sub
End Class
输出:
The members of the Colors enum are: Red Green Blue Yellow The members of the Styles enum are: Plaid Striped Tartan Corduroy
示例2: Example
Public Enum SignMagnitude As Integer
Negative = -1
Zero = 0
Positive = 1
End Enum
Module Example
Public Sub Main()
Dim names() As String = [Enum].GetNames(GetType(SignMagnitude))
For Each name In names
Console.WriteLine("{0,3:D} 0x{0:X} {1}",
[Enum].Parse(GetType(SignMagnitude), name),
name)
Next
End Sub
End Module
输出:
0 0x00000000 Zero 1 0x00000001 Positive -1 0xFFFFFFFF Negative