How can I print the contents of an array horizontally?

.net, arrays, c#

Solution

You are probably using `Console.WriteLine` for printing the array.

int[] array = new int[] { 1, 2, 3 };
foreach(var item in array)
{
    Console.WriteLine(item.ToString());
}

If you don't want to have every item on a separate line use `Console.Write`:

int[] array = new int[] { 1, 2, 3 };
foreach(var item in array)
{
    Console.Write(item.ToString());
}

or `string.Join<T>` (in .NET Framework 4 or later):

int[] array = new int[] { 1, 2, 3 };
Console.WriteLine(string.Join(",", array));

Problem

Why doesn't the console window print the array contents horizontally rather than vertically? Is there a way to change that? How can I display the content of my array horizontally instead of vertically, with a `Console.WriteLine()`? For example: ``` int[] numbers = new int[100] for(int i; i < 100; i++) { numbers[i] = i; } for (int i; i < 100; i++) { Console.WriteLine(numbers[i]); } ```

Original source

Related problems