开发者

Create a enum or enum equivalent that returns string (enum returns int) in .NET

开发者 https://www.devze.com 2022-12-15 05:43 出处:网络
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:

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 ret开发者_高级运维urns an integer value as enum. How do I get the string name of an enum.

 Dim targetUri As String = setting.protocolType & "://www.example.com"


To get the string value of the Enum, use Enum.ToString()

0

精彩评论

暂无评论...
验证码 换一张
取 消