For logging purposes, I need to output a double[,] to the log file. So I need to represent the array as a string.
The following code gets the job done using basic C# 1 features, but I was wondering if there is a more elegant solution using Linq:
private static string OneRowPerLine(double[,] numbers)
{
var ret = new StringBuilder();
for(var i=numbers.GetLowerBound(0);i<=numbers.GetUpperBound(0);i++)
{
for (var j = numbers.GetLowerBound(1); j <= numbers.GetUpperBound(1); j++)
{
if(j>numbers.GetLowerBound(1))
{
ret.Append(",");
}
ret.Append(numbers[i, j]);
}
ret.Append(Environment.NewLine);
}
return ret.ToString();
}