Content Obsolete

This content is no longer current. Our recommendation for up to date content:

Enumerations and the switch Decision Statement - 19

Download this episode

Download Video

Download captions

Download Captions


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.

Download the source code for Enumerations and the switch...



Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image

      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()
        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")
        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)
            Console.WriteLine("How Are You?")
          End If
        End Sub
        Enum SuperHeros
        End Enum
      End Module

      When you use Enumerations it can be of any value that the underlying type can be. 

      See Example Code above


    • User profile image

      @AdamSpeight2008:Awesome, awesome comment.  Thank you!  When we re-do this video I'll make sure to revise as you have advised.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.