Below is the simplest solution.
Console.WriteLine("[{0}]", string.Join(", ", array));
Conclusion: [1, 2, 3, 4, 5]
Another short solution
Array.ForEach(array, val => Console.Write("{0} ", val));
Conclusion: 1 2 3 4 5 , or, if you need to add, add,, use below
int i = 0; Array.ForEach(array, val => Console.Write(i == array.Length -1) ? "{0}" : "{0}, ", val));
Conclusion: 1, 2, 3, 4, 5
ElasticCode Aug 14 '19 at 23:25 2019-08-14 23:25
source share