Enumerations and the switch Decision Statement - 19
- Posted: Nov 21, 2011 at 9:28 AM
- 16,531 Views
- 2 Comments
Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
Right click “Save as…”
Classes can contain many different types of information, not just Properties and Methods. We begin demonstrating the use of Enumerations because often in the .NET Framework Class Library, properties can only be set to a pre-determined subset of possible values. To illustrate this point we create our own custom enumeration, and then utilize it in a simple application that demonstrates a third Decision statement, the switch. We demonstrate some Visual Studio IDE magic that will automatically implement code blocks for all possible enumeration values.
Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation,
please create a new thread in our Forums,
or
Contact Us and let us know.
Follow the Discussion
Oops, something didn't work.
What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in. You need to be signed in to Channel 9 to use this feature.What does this mean?
Following an item on Channel 9 allows you to watch for new content and comments that you are interested in and view them all on your notifications page.sign up for email notifications?
A found it a little misleading when you (Bob) refer to the ComplexIfStatement, kind of inferred or suggested that the Select Case decision statement can't do what the ComplexIfStatement does. (Especially with Option Strict Off)
See Example Below.
Module Module1 Sub Main() SelectCase_Example() Console.WriteLine() SuperHero_Example() Console.ReadLine() End Sub Public Sub SelectCase_Example() Console.WriteLine("Select Case Example") Dim value = 42 Select Case value Case Is < 1, Is > 100 : Console.WriteLine("Out of bounds") Case 23, 42, Is > 90 : Console.WriteLine("You Found one of the special numbers") Case Else Console.WriteLine("Not one of special numbers") End Select End Sub Public Sub SuperHero_Example() Console.WriteLine("SuperHero Example") GreetSuperHero(11) GreetSuperHero(SuperHeros.Batman) End Sub Public Sub GreetSuperHero(ByVal superhero As SuperHeros) Dim IsMemberOfSuperHeros = [Enum].IsDefined(GetType(SuperHeros), superhero) If IsMemberOfSuperHeros Then Console.WriteLine("Hello: {0}", superhero.ToString) Else Console.WriteLine("How Are You?") End If End Sub Enum SuperHeros Superman Batman Spiderman End Enum End ModuleWhen you use Enumerations it can be of any value that the underlying type can be.
See Example Code above
@AdamSpeight2008:Awesome, awesome comment. Thank you! When we re-do this video I'll make sure to revise as you have advised.
Remove this comment
Remove this thread
close