How to write a function that print int array in console application C#

1 Answer

0 votes
using System;

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

            printArray(numbers);
            printArray(null); // No print
            printArray(new int[0]); // No print
        }
        static void printArray(int[] arr)
        {
            if (arr != null && arr.Length > 0)
            {
                foreach (int val in arr)
                    Console.WriteLine(val);
            }
        }
    }
}

/*
run:
  
1
2
3
4
5

*/


answered Feb 26, 2015 by avibootz
...