「VB.NET入門」For文で列挙型(Enum型)の名前と値を取得するサンプル

サンプルコード

Module ModuleTest
 
    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("enum 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

 

VB.net

Posted by arkgame