How to print array directly in C#

1 Answer

0 votes
using System;

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

            // option 1
            Array.ForEach(arr, x => Console.WriteLine(x));

            // option 2
            Console.WriteLine("arr: {0}", string.Join(", ", arr)); 
        }
    }
}
/*
run:
1
2
3
4
5
6
7

arr: 1, 2, 3, 4, 5, 6, 7
*/



answered Sep 12, 2014 by avibootz

Related questions

1 answer 250 views
1 answer 242 views
1 answer 183 views
1 answer 488 views
1 answer 325 views
...