Dr. Rajesh Rolen
Dr. Rajesh Rolen

Reputation: 14285

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

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"

Upvotes: 0

Views: 566

Answers (1)

Gabriel McAdams
Gabriel McAdams

Reputation: 58293

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

Upvotes: 2

Related Questions