How to print int array in C#

3 Answers

0 votes
using System;

class Program
{
    static void printArray(int[] arr) {
        for (int i = 0; i < arr.Length; i++ ) {
            Console.Write("{0} ", arr[i]);
        }
        Console.WriteLine();
    }
    static void Main() {
        int[] arr = new int[] { 2, 4, 6, 1, 9, 3 };

        printArray(arr);
    }
}




/*
run:

2 4 6 1 9 3 

*/

 



answered Jul 23, 2020 by avibootz
0 votes
using System;

class Program
{
    static void printArray(int[] arr) {
        Console.WriteLine(string.Join(" ", arr));
    }
    static void Main() {
        int[] arr = new int[] { 2, 4, 6, 1, 9, 3 };

        printArray(arr);
    }
}




/*
run:

2 4 6 1 9 3 

*/

 



answered Jul 23, 2020 by avibootz
0 votes
using System;

class Program
{
    static void printArray(int[] arr) {
        foreach (int n in arr) {
            Console.Write("{0} ", n);
        }
        Console.WriteLine();
    }
    static void Main() {
        int[] arr = new int[] { 2, 4, 6, 1, 9, 3 };

        printArray(arr);
    }
}




/*
run:

2 4 6 1 9 3 

*/

 



answered Jul 23, 2020 by avibootz
edited Dec 17, 2020 by avibootz

Related questions

1 answer 178 views
1 answer 431 views
1 answer 167 views
167 views asked Feb 14, 2017 by avibootz
1 answer 116 views
...