vb.net 枚举类型

前端之家收集整理的这篇文章主要介绍了vb.net 枚举类型前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
定义枚举类型 :

Enum 类型名称

成员名=表达式(常量)

End Enum

创建一个一星期的 枚举类型 :

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


运行效果

原文链接:https://www.f2er.com/vb/259422.html

猜你在找的VB相关文章