Results 1 to 3 of 3

Thread: [RESOLVED] [2008] LINQ query on 2-Dimensional Arrays

Threaded View

  1. #1

    Thread Starter
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Resolved [RESOLVED] [2008] LINQ query on 2-Dimensional Arrays

    What is the correct way to query a 2-D array with LINQ.

    e.g.
    What will be the LINQ equivalent of the following code:

    vb.net Code:
    1. Dim myArray(10, 1) As String
    2. '--- Fill the entire array ---
    3. myArray(0, 0) = "some text 0"
    4. myArray(0, 1) = "value 0"
    5. myArray(1, 0) = "some text 1"
    6. myArray(1, 1) = "value 1"
    7. myArray(2, 0) = "some text 2"
    8. myArray(2, 1) = "value 2"
    9. '....
    10.  
    11. Dim selection As New List(Of ListItem)
    12. For i As Integer = 0 To myArray.GetLength(0) - 1
    13.     selection.Add(New ListItem(myArray(i, 0), myArray(i, 1)))
    14. Next

    I have tried things like these, but they don't work:
    vb.net Code:
    1. Dim selection = From item In myArray _
    2.                 Select New ListItem With {.Text = item(0), .Value = item(1)}
    3.  
    4. Dim selection = From item In myArray _
    5.                 Select New ListItem(item(0), item(1))

    Pradeep
    Last edited by Pradeep1210; Apr 10th, 2008 at 01:44 AM.
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width