Create a gist now

Instantly share code, notes, and snippets.

Pretty Print Array of Arrays
[[1,2,3],[3,5,7],[2,4,6]]
[[1,2,3]]
[[1,2,3],[3,5,7,9,11],[2,4,6]]
public string PrettyPrintArrayOfArrays(int[][] arrayOfArrays)
{
if (arrayOfArrays == null)
return "";
var prettyArrays = new string[arrayOfArrays.Length];
for (int i = 0; i < arrayOfArrays.Length; i++)
{
prettyArrays[i] = "[" + String.Join(",", arrayOfArrays[i]) + "]";
}
return "[" + String.Join(",", prettyArrays) + "]";
}
public void PrettyPrintArrayOfArraysTests()
{
int[][] ints = new int[3][] { new int[] { 1, 2, 3 }, new int[] { 3, 5, 7 }, new int[] { 2, 4, 6 } };
var pretty = PrettyPrintArrayOfArrays(ints);
Console.WriteLine(pretty);
ints = new int[1][] { new int[] { 1, 2, 3 } };
pretty = PrettyPrintArrayOfArrays(ints);
Console.WriteLine(pretty);
ints = new int[3][] { new int[] { 1, 2, 3 }, new int[] { 3, 5, 7, 9, 11 }, new int[] { 2, 4, 6 } };
pretty = PrettyPrintArrayOfArrays(ints);
Console.WriteLine(pretty);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment