我正在为我的项目使用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
原文地址:https://www.jb51.cc/vb/256011.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。