创建在 .NET 中返回字符串(枚举返回 int)的枚举或等效枚举
我有一个 URL,比如说 http://www.example.com
。有时,我需要发送 HTTP,有时,我需要发送 HTTPS。为此,我创建了一个枚举:
Private _protocol As Protocol
Enum Protocol
HTTP
HTTPS
End Enum
Public Property protocolType() As Protocol
Get
Return _protocol
End Get
Set(ByVal value As Protocol)
_protocol = value
End Set
End Property
现在,当我从协议类型返回值时,它会返回一个整数值作为枚举。如何获取枚举的字符串名称。
Dim targetUri As String = setting.protocolType & "://www.example.com"
I have a URL, lets say http://www.example.com
. Sometimes, I need to send HTTP and other times, I need to send HTTPS. For that, I created an enum:
Private _protocol As Protocol
Enum Protocol
HTTP
HTTPS
End Enum
Public Property protocolType() As Protocol
Get
Return _protocol
End Get
Set(ByVal value As Protocol)
_protocol = value
End Set
End Property
Now, when I get the value back from protocoltype, it returns an integer value as enum. How do I get the string name of an enum.
Dim targetUri As String = setting.protocolType & "://www.example.com"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要获取 Enum 的字符串值,请使用 Enum.ToString()
To get the string value of the Enum, use Enum.ToString()