How to convert string to enum in vb.net application
I am working on .Net application Can anyone suggest me how do I convert the string into an enum or an vice a versa, this is because I've come across the situation on a number of occasions when coding where I've wanted to convert from a string to an enum but unable to do that.
Re: How to convert string to enum in vb.net application
Enums are a powerful construction in C# and other programming languages I will provide you the little hint about how to go further, if you are on the right track and proper understanding of VB.Net then you should get an idea about how to start for your application, and if not then let me know i will give more clues to you.
object Enum.Parse(System.Type enumType, string value, bool ignoreCase);
Re: How to convert string to enum in vb.net application
Are you building a great new web application? Another more flexible approach (albeit much slower) is to adhorn each Enum value with a DescriptionAttribute, and to use reflection to grab that, <span style="background-color:yellow;">this text would have a yellow background</span> I perfer HTML over scripting because HTML is a bit easier to understand a lot of the time, but I wouldn't just blow this off because it can have some advantages some of the time
Re: How to convert string to enum in vb.net application
Pass the string value equivalent to the value in the enum. You might want to put a try..catch around the TryParse method in case a value not in the enum is provided, when you are working with finite sets such as fruits, days of the week or colors. Visual Studio's Intellisense is very nice with Enums because it lists all the options for the programmer to choose from.