How to print one dimensional array of integers in C#

4 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 2, 5, 6, 6, 2 };

            for (int i = 0; i < arr.Length; i++)
                Console.Write("{0,3}", arr[i]);
        }
    }
}

/*
run:
   
  1  2  3  2  5  6  6  2
  
*/

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 2, 5, 6, 6, 2 };

            foreach (var item in arr)
                Console.Write(item.ToString() + " ");
        }
    }
}

/*
run:
   
1 2 3 2 5 6 6 2
  
*/

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 2, 5, 6, 6, 2 };

            Console.WriteLine(string.Join(",", arr));
        }
    }
}

/*
run:
   
1,2,3,2,5,6,6,2
  
*/

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 2, 5, 6, 6, 2, 1 };

            Console.WriteLine(string.Join(" ", arr));
        }
    }
}

/*
run:
   
1 2 3 2 5 6 6 2 1
  
*/

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz
...