Showing posts with label Enum. Show all posts
Showing posts with label Enum. Show all posts

Monday, April 27, 2009

Using Enums

Hi Guys,
Here are the useful methods that can be utilized against the Enums:


Public Enum WeekDays
Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
End Enum

1. The following method helps easily to load the enum names to the combo/list box
Example:
lstWeekDays.Items.AddRange([Enum].GetNames(GetType(WeekDays)))
2. The following method helps easily to load all the enum values at once to an array
Example:
dim myArray as Array = [Enum].GetValues(GetType(WeekDays))
3. The following method helps easily to determine if a name or a value exists in the Enum
Example:

if [Enum].IsDefined(GetType(WeekDays), "Sunday") Then 'do something
If [Enum].IsDefined(GetType(WeekDays), 1) Then ' do something its Monday