Print Array Contents Horizontally Using C#



Set an array.

int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 };

Now, if you will print this array using a loop and new line, then the arrays will be visible vertically.

To work it horizontally, use the Join() method and set spaces to separate array elements.

string.Join(" ", array)

Let us see the complete code.

Example

 Live Demo

using System;
using System.Linq;
using System.IO;
class Program {
   static void Main() {
      int[] array = new int[] { 50, 100, 150, 200, 250, 300, 350, 400 };
      Console.WriteLine(string.Join(" ", array));
   }
}

Output

50 100 150 200 250 300 350 400
Updated on: 2020-06-22T15:29:28+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements