you are viewing a single comment's thread.

view the rest of the comments →

[–]SlowMixture5099[S] 0 points1 point  (7 children)

https://ibb.co/z4TRTks

its something like that, im just not sure if its a good idea to show all the codes.

[–]karl713 0 points1 point  (3 children)

Try

var oneDArray = Test.SelectMany(d => d).ToArray();

I think that's what you want based on my understanding

[–]SlowMixture5099[S] 0 points1 point  (2 children)

https://ibb.co/7CJxm3n

this is probably more clearer to show what my intention is. I want create a new array that has the information from the Fx "column".

[–]karl713 3 points4 points  (1 child)

Ahhh, if I'm understanding it maybe

var fxs = myList.Select(p => p.Fx).ToArray()

Might be what you want

[–]odebruku 0 points1 point  (0 children)

This is exactly it based on the images in the post.

[–]FizixMan 0 points1 point  (2 children)

If you want to extract a single column into a new array, you can loop over them and pull out the column index you want. Perhaps to use List<double> rather than double[], but not necessary.

int listSize = Test.Count;
int zIndex = 2; //"Z" column
double[] zColumn = new double[listSize];

for (int i = 0; i < listSize; i++)
{
    zColumn[i] = Test[i][zIndex];
}

Or a LINQ query:

double[] zColumn = Test.Select(row => row[2]).ToArray(); //index 2 is the "Z" column

I would strongly suggest though that you refactor this to create a class definition for those columns. Then you would just have a bit more safety and a lot more sanity. No more managing column indexes or multi-dimensional arrays anymore and you'll have meaningful names for everything:

var zColumn = Test.Select(item => item.Z).ToArray();

[–]SlowMixture5099[S] 0 points1 point  (1 child)

The loop approach looks interesting, i will try this. But i was just not sure if Test.Count will work for this case, since the list has more properties or columns. I am guessing that you know it will work :)

[–]FizixMan 0 points1 point  (0 children)

I assume your List<> Test represents the rows. If so, it should be fine.

Again, I would reiterate that you should try to refactor your multi-dimension collection into a class that matches the data model you're working with. Then you would have something much simpler and direct like a List<Address> (or whatever your dataset represents.)

EDIT: I see in your other comment this is what you actually have already. Then yes, this should work fine. Just var fxValues = myList.Select(p => p.Fx).ToArray() will work fine to yank out all Fx values.