Linq/Query unite arrays

Hello, I have three arrays with different lenghts.

Example: { “1”, “2”, “3” }, { “4” }, {“5”, “6”}
I want to group elements on the same positions. { “1”, “4”, “5”}, { “2”, “6” }, { “3” }

I can do it into while loop, but I want to group them using linq or query. (in one line)

Hi @YoungFave
Still not getting the idea on how output should be ?

I want to construct html table using this arrays.

<tr array1(0), array2(0), array3(0) </tr
<tr array1(1), array2(1), array3(1) </tr

and so on

Hi,

I guess you want to group the values as array based on the positions like all the element of 1st position to one array and 2nd positions as array 2.

1 Like

Yes, help me to do it!

I have a rough idea with combining all these 1d array into 2d array and it becomes one array. So you can loop them in Linq to frame as different array. I’ll try once.

@YoungFave
Variables:
grafik

Flow:
grafik

LINQ:

(From a In {arr1,arr2,arr3}
Select ta = a.Select(Function (x,i) Tuple.Create(i,x))
From t In ta 
Group t By t.Item1 Into grp=Group
Let ga = grp.Select(Function (g) g.Item2).toArray
Select grs = ga).toList

done with the help of position tuples created by an indexed select

Check:
grafik

2 Likes

for doing the above the grouping will not serve, as with different length arrays, shorter ones need to be filled up on common length

grafik

(From i In Enumerable.Range(0,{arr1,arr2,arr3}.Max(Function (a) a.Length))
Let ra = {arr1,arr2,arr3}.Select(Function (x) If(x.Length <= i,"",x(i))).toArray
Select r=ra).toList

grafik

Feel free to combine {arr1,arr2,arr3} into a variable and will use later this within the LINQ

2 Likes

Thank you a lot

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.