Showing combined enum results as string

  • Thread starter Thread starter wingers
  • Start date Start date
W

wingers

Guest
Hi

Hopefully this will make sense, as couldn't get wording right for title!

I have an Enum, and I set a string property to one or more of the enum values

I then want to be able to show it on screen, but showing the Enum name to string not just the enum value

The below code explains my question better - as you can see if I just store color.red then when I show mycolors.tostring it correctly shows "Red"

But if I store multiple values from my enum, then .tostring shows the number of all values added up e.g. 13, when I want it to show each entries string value e.g. "Red, Blue, Yellow"

Not sure where I am going wrong, or how best to achieve my requirement

Thanks


Public Class Form1

Enum Colors
Red = 1
Green = 2
Blue = 4
Yellow = 8
End Enum


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myColors As Colors = Colors.Red
msgbox("myColors = " & myColors.tostring)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim myColors As Colors = Colors.Red Or Colors.Blue Or Colors.Yellow
msgbox("myColors = " & myColors.tostring)
End Sub

End Class









Darren Rose

Continue reading...
 
Back
Top