Populate list with set of data at instantiation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #1

    Populate list with set of data at instantiation

    Am I going crazy? I'm sure I recall seeing a method of instantiating a list and populating it using some method akin to:

    Dim myList As List(Of Integer) {0, 4, 9, 10, 50}

    It appears not to be the correct syntax and I can't work out what it's supposed to be...and maybe my head's not working properly today because I can't even figure out what to type into the search engine to bring back relevant useful results...anyon e?
  • Shashi Sadasivan
    Recognized Expert Top Contributor
    • Aug 2007
    • 1435

    #2
    [CODE=cpp]List<int> i = new List<int>(new int[] { 1, 2, 3, 4, 5, });[/CODE]
    [CODE=vbnet]Dim i As New List(Of Integer)(New Integer() {1, 2, 3, 4, 5}) [/CODE]

    does that help?

    Comment

    • balabaster
      Recognized Expert Contributor
      • Mar 2007
      • 798

      #3
      Originally posted by Shashi Sadasivan
      [CODE=cpp]List<int> i = new List<int>(new int[] { 1, 2, 3, 4, 5, });[/CODE]
      [CODE=vbnet]Dim i As New List(Of Integer)(New Integer() {1, 2, 3, 4, 5}) [/CODE]

      does that help?
      Thank you - I didn't think I was going crazy, why I couldn't figure that out for myself is beyond me.

      Comment

      Working...