在VB.Net中定义字符串ENUM

我正在为我的项目使用Window应用程序。有情况我需要定义字符串枚举并在我的项目中使用它。

Dim PersonalInfo As String = "Personal Info"
Dim Contanct As String = "Personal Contanct"

    Public Enum Test
        PersonalInfo
        Contanct
    End Enum

现在我想要将该变量PersonalInfo和Contract作为“个人信息”和“个人连接”的价值。

如何使用ENUM获取此值?或任何其他方式来做到这一点。

提前致谢…

你可以创建一个新的类型
''' <completionlist cref="Test"/>
Class Test

    Private Key As String

    Public Shared ReadOnly Contact  As Test = New Test("Personal Contanct")
    Public Shared ReadOnly PersonalInfo As Test = New Test("Personal Info")

    Private Sub New(key as String)
        Me.Key = key
    End Sub

    Public Overrides Function ToString() As String
        Return Me.Key
    End Function
End Class

当你使用它,它看起来像一个枚举:

Sub Main

    DoSomething(Test.Contact)
    DoSomething(Test.PersonalInfo)

End Sub

Sub DoSomething(test As Test)
    Console.WriteLine(test.ToString())
End Sub

输出

Personal Contanct Personal Info

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...