【问题标题】:Create a enum or enum equivalent that returns string (enum returns int) in .NET在 .NET 中创建一个返回字符串(枚举返回 int)的枚举或枚举等效项
【发布时间】:2009-12-30 05:15:45
【问题描述】:

我有一个 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"

【问题讨论】:

    标签: vb.net string enums


    【解决方案1】:

    要获取枚举的字符串值,请使用Enum.ToString()

    【讨论】:

    • 非常感谢。我认为它会将 2 转换为 "2" int 到 string(int)
    猜你喜欢
    • 2012-11-27
    • 2018-11-24
    • 1970-01-01
    • 2022-01-12
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多