Monthly Archives: July 2004

QA: Using Enum.Parse to Convert a String to an Enumeration Value

Published on: Author: Rob Windsor 1 Comment

Question:I have a string that holds the name of a value from an enumeration. How do I “cast“ that to the actual enumeration type? Answer:You can use the Parse method of the Enum class to do this conversion for you. Some sample VB code is shown below. Dim dr As DialogResultdr = CType([Enum].Parse(GetType(DialogResult), “Cancel”), DialogResult)MsgBox(dr.ToString)