I am wanting to efficiently convert a multidimensional object array into a list of joined arrays.
Firstly, I have converted the 2D array into a list of arrays:
object[,] data; // This contains all the data.
int count = 0;
List<string[]> dataList = data.Cast<string>()
.GroupBy(x => count++ / data.GetLength(1))
.Select(g => g.ToArray())
.ToList();
And now what I want to do is create a List where I trim and then join all the data in each array. To clarify what I mean, I can do this using:
List<string> dataListCombined = new List<string>();
foreach (string[] s in dataList)
{
for (int i = 0; i < s.Length; i++)
{
s[i] = s[i].Trim();
}
dataListCombined.Add(string.Join(",", s));
}
but i just want to know if there is a more efficient way of doing it. Can I alter LINQ Im using above to do it? Thanks
>` instead of a `List`. In general, lists are so much easier to work with than arrays.
– Casey Crookston Sep 18 '19 at 13:52