Sponsored Ad

Sunday, May 6, 2012

Return an Array from a Method in C#

This program is a example of returning an integer array from a method. Create an integer array in the function and return it. Remember that the function return type should be array of integer.

Return an Array from a Method in C#

using System;

namespace ConsoleHub
{
    class Programs
    {       
        static void Main(string[] args)
            {
                int[] ReturnArray = ArrayFactory();

                Console.WriteLine("The Return Array is: ");
                foreach (int d in ReturnArray)
                {
                    Console.Write(" {0}", d);
                }

                Console.ReadLine();
            }

            static int[] ArrayFactory()
            {
                int[] NumberQueue = { 5, 6, 3, 8, 9 };
                return NumberQueue;
            }       
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates