Enum.Parse C# and VB.NET
Enum.Parse is easy to remember with C# but I always forget the VB.Net syntax because the Enum keyword is a keyword and a class.
C#
40 public enum ClickType
41 {
42 Submit = 1,
43 Reset = 2,
44 None = 0
45 }
46
47 ClickType eClick;
48 string sTemp = "Submit";
49
50 eClick = (ClickType) Enum.Parse(typeof(ClickType), sTemp, true);
VB.NET
263 Public Enum ClickType
264 Submit = 1
265 Reset = 2
266 None = 0
267 End Enum
268
269 Dim eClick As ClickType
270 Dim sTemp As String = "Submit"
271
272 eClick = CType([Enum].Parse(GetType(ClickType), sTemp), ClickType)
Comment Notification
If you would like to receive an email when updates are made to this post, please register here
Subscribe to this post's comments using
Comments
What do you think?