I can't seem to figure out why item within a List is not being appended to a Jagged Array.
I have the following code
var list = new List<(double,double)>{
( -99.8299313, 32.2840118),
( -99.8293304, 32.2840118),
};
var jaggedArray = new double[list.Count()][];
foreach (var item in list)
{
var s = item.Split(",");
jaggedArray.Append(new string[] {
Convert.ToDouble(s[0]),
Convert.ToDouble(s[1]) })
.ToArray();
}
When I inspect the array it's empty? What am I doing wrong?
I have even declared the size of the array using list.Count() but its always empty?
From
Enumerable.Appenddocs:Which is demonstrated by the code sample there:
So one thing you can do is reassign the
jaggedArray(after fixing the issue I've mentioned in the comment):Though it would not be the most effective approach. A better one would be to just go with LINQ all the way:
Note that
new string[] { s[0], s[1] }will throw if there is less than 2 elements, consider usingWhere(s => s.Length > 1)to filter out such cases if appropriate.