加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在VB.Net中定义字符串ENUM

发布时间:2020-12-16 23:59:26 所属栏目:大数据 来源:网络整理
导读:我正在为我的项目使用Window应用程序。有情况我需要定义字符串枚举并在我的项目中使用它。 即 Dim PersonalInfo As String = "Personal Info"Dim Contanct As String = "Personal Contanct" Public Enum Test PersonalInfo Contanct End 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读