本文整理匯總了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