I am wondering if two int arrays can theoretically be merged into a single array of structures using only LINQ, where each array going into its respective field?
So let's say we have 2 int arrays called numbers_raw and categories_raw, and class Record with 2 fields.
Using procedural code it looks like this:
class Record {
public int number;
public int category;
}
int[] numbers_raw = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 14, -4 };
int[] categories_raw = { 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2 };
var records = new List<Record>();
for (int ii = 0; ii < numbers_raw.Length; ii++) {
records.Add(new Record { number = numbers_raw[ii], category = categories_raw[ii] });
}
And if we had only 1 array and 1 field we could do it like this:
var records = numbers_raw.Select(x => new Record { number = x });
But I am not sure how to do it in such a way that both arrays are used, categories_raw going into the category field and numbers_raw goes into number field.
I am not sure if it is at all possible using LINQ.