Advertisement
Guest User

Untitled

a guest
Sep 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 0.76 KB | None | 0 0
  1. Module Module1
  2.  
  3.     Dim UnknownEnumerator As String = "Unknown"
  4.  
  5.     Enum Fruit
  6.         Apple
  7.         Banana
  8.         Pear
  9.         Mango
  10.     End Enum
  11.  
  12.     Sub Main()
  13.         Dim fruitType As Integer = 0
  14.         Console.WriteLine(ConvertEnumToString(Of Fruit)(fruitType))
  15.         Console.ReadKey()
  16.     End Sub
  17.  
  18.     Public Function ConvertEnumToString(Of T)(value As Integer) As String
  19.         Dim myList As List(Of T) = [Enum].GetValues(GetType(T)).Cast(Of T).ToList()
  20.  
  21.         For Each item As T In myList
  22.             Dim myInt As Integer = CInt(item)
  23.             Console.WriteLine(item.ToString())
  24.             'If item = DirectCast(value, T) Then Return item.ToString()
  25.         Next
  26.  
  27.         Return UnknownEnumerator
  28.     End Function
  29.  
  30. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement