vb.net 枚举类型

页面导航:首页 > 软件编程 > vb.net > vb.net 枚举类型

vb.net 枚举类型

来源: 作者: 时间:2016-01-18 16:54 【

定义枚举类型 :Enum 类型名称成员名=表达式(常量)End Enum创建一个一星期的 枚举类型 :[vb]Module Module1 Enum days sunday = 0 monday = 1 yuesday = 2 wednesday = 3 thursday = ...

定义枚举类型 :
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

运行效果 :

 \

 

Tags:

文章评论

最 近 更 新
热 点 排 行
Js与CSS工具
代码转换工具

<