vb.net 枚举类型
定义枚举类型 :
Enum 类型名称
成员名=表达式(常量)
End Enum
创建一个一星期的 枚举类型 :
[vb]
Module Module1
Enum days
sunday = 0
monday = 1
yuesday = 2
wednesday = 3
thursday = 4
friday = 5
saturday = 6
End Enum
Sub Main()
Dim showday As days
showday = days.thursday
Dim myday As String
Console.WriteLine("枚举days")
For Each myday In [Enum].GetNames(GetType(days))
Console.Write("{0} ", myday)
Next
Console.ReadLine()
Dim i As Integer
For Each i In [Enum].GetValues(GetType(days))
Console.WriteLine("一周中的第{0}天是{1}", i, [Enum].GetName(GetType(days), i))
Next
Console.ReadLine()
End Sub
End Module
Module Module1
Enum days
sunday = 0
monday = 1
yuesday = 2
wednesday = 3
thursday = 4
friday = 5
saturday = 6
End Enum
Sub Main()
Dim showday As days
showday = days.thursday
Dim myday As String
Console.WriteLine("枚举days")
For Each myday In [Enum].GetNames(GetType(days))
Console.Write("{0} ", myday)
Next
Console.ReadLine()
Dim i As Integer
For Each i In [Enum].GetValues(GetType(days))
Console.WriteLine("一周中的第{0}天是{1}", i, [Enum].GetName(GetType(days), i))
Next
Console.ReadLine()
End Sub
End Module
运行效果 :