Link to home
Start Free TrialLog in
Avatar of Mike Eghtebas
Mike EghtebasFlag for United States of America

asked on

Use List(of Type)

Below, stying with:

 Dim value As New List(Of Importance)

Or modifying it a bit, I want to print the items in Enum Importance. I want to practice the use List(of Type).

This code doesn't work. Could you please help to make it work possibly using the above objective.
  Enum Importance
        Critical = 4
        Important = 3
        None = 0
        Regular = 2
        Trivial = 1
    End Enum

    Private Sub Enum_Select_TypoOf()
        Dim value As New List(Of Importance)
        Dim i As Integer
        For i = 0 To value.Count
            Console.WriteLine(value(i))
        Next i
        Console.ReadLine()
    End Sub

Open in new window

SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
kaufmed is thinking the same way as I - the enum itself is no good example. It is like having only prizes, without any article description. If course you can sort them, but what does the result mean then?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Eghtebas

ASKER

Thanks to all. I had easier solution to print Enum Importance. My goal was to wrap my mind around use of List(Of Type). Kaufmed explanation was helpful.

It_saige's solution brings me to a point where I can see how use of List maybe is not the best use in this case. I will try List(Of Type) with other settings to learn more about it.

Mike
Here is an example of what I was looking for:

Enum Code As Byte
        Small = 0
        Medium = 1
        Large = 2
 End Enum

  Sub Main()
        Enum_Types()     'http://www.dotnetperls.com/enum-vbnet
  End Sub

Private Sub Enum_Types()
        ' The value is represented in a byte.
        Dim value As Code = Code.Medium
        'Console.WriteLine(value)
        For Each i In [Enum].GetValues(GetType(Code))
            Console.WriteLine(i)
        Next
        Console.ReadLine()
    End Sub

Output:
small
medium
large

Open in new window