ToString()

枚举上的 ToString 方法返回枚举的字符串名称。例如:

Module Module1
    Enum Size
        Small
        Medium
        Large
    End Enum

    Sub Main()
        Dim shirtSize As Size = Size.Medium
        Dim output As String = shirtSize.ToString()
        Console.WriteLine(output)  ' Writes "Medium"
    End Sub
End Module

但是,如果需要枚举的实际整数值的字符串表示,则可以将枚举转换为 Integer 然后调用 ToString

Dim shirtSize As Size = Size.Medium
Dim output As String = CInt(shirtSize).ToString()
Console.WriteLine(output)  ' Writes "1"