我正在为我的项目使用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