1

How can I retrieve the name of a enumeration as string? I know you can get the integral value, but this is not what I would like.

I searched the www but it didn't show any good samples.

I made a example class to proper show what I require.

Class test Public Property PipeEndTreatment As PipeEndTreatmentEnum Public Enum PipeEndTreatmentEnum SetOn SetIn Offset OffsetFlush End Enum Private Sub TestEnumNameValue() PipeEndTreatment = PipeEndTreatmentEnum.SetOn Dim StringValue As String StringValue = "SetOn" ' This value needs to be generated from the PipeEndTreatment property End Sub End Class 
2
  • 1
    StringValue = PipeEndTreatment.ToString() Commented Nov 16, 2016 at 13:48
  • Possible duplicate of Convert Enum to String Commented Nov 16, 2016 at 14:11

1 Answer 1

4

Just use ToString(), e.g. PipeEndTreatmentEnum.SetOn.ToString().

Here's another way in case you like longer ways:

[Enum].GetName(PipeEndTreatmentEnum.SetOn.GetType(), PipeEndTreatmentEnum.SetOn) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.