- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print the contents of array 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
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
Advertisements