How to get 2D array from table 'Linq'

Mansour_Dalir 2,036 Reputation points
2023-12-22T18:01:12.18+00:00
     Dim MyDataTable As New DataTable
        MyDataTable.Columns.Add("C1")
        MyDataTable.Columns.Add("C2")
        MyDataTable.Columns.Add("C3")
        MyDataTable.Rows.Add({1, "A"})
        MyDataTable.Rows.Add({2, "C"})
        MyDataTable.Rows.Add({3, "F"})
        
         dim SpecificColumns() as String={"C2","C3"}
        'Need 2D Array Result From specific columns
        Dim Resalt As String () () = MyDataTable.Columns("C2") And MyDataTable.Columns("C3")

Like This but By From Data Table ..Thank

   Dim stt5 As String = "1=A,2=C,3=F"
   Dim ResultArray As String()() = stt5.Split(","c).Select(Function(p) p.Split("="c).Take(2).Select(Function(s) s).ToArray).ToArray

Developer technologies | VB
{count} votes

Accepted answer
  1. Viorel 122.7K Reputation points
    2023-12-22T19:58:03.9566667+00:00

    Check this code:

    Dim result As String()() = MyDataTable.AsEnumerable.Select(Function(r) r.ItemArray.Select(Function(x) x.ToString).ToArray).ToArray
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.