The below solution is the simplest one:
Console.WriteLine("[{0}]", string.Join(", ", array));
Output: [1, 2, 3, 4, 5]
Another short solution:
Array.ForEach(array, val => Console.Write("{0} ", val));
Output: 1 2 3 4 5
. Or if you need to add add ,
, use the below:
int i = 0;
Array.ForEach(array, val => Console.Write(i == array.Length -1) ? "{0}" : "{0}, ", val));
Output: 1, 2, 3, 4, 5