2009-12-30 6 views
0

J'ai une URL, disons http://www.example.com. Parfois, j'ai besoin d'envoyer HTTP et d'autres fois, j'ai besoin d'envoyer HTTPS. Pour cela, je créé un ENUM:Créer un équivalent enum ou enum qui renvoie une chaîne (enum returns int) dans .NET

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 

Maintenant, quand je reçois la valeur de retour de ProtocolType, il retourne une valeur entière ENUM. Comment puis-je obtenir le nom de chaîne d'une énumération.

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

Répondre

2

Pour obtenir la valeur de chaîne de la Enum, utilisez Enum.ToString()

+0

lot Merci. je pensais qu'il va convertir comme 2 en "2" int en string (int) –