Sponsored Ad

Wednesday, May 5, 2010

How to pass and return arrays in methods using C#

 

This sample program will help you to pass arrays and returns arrays from a function in C#. use the below program to develop complex functions to return and accept values.

Output:

How to pass and return arrays in methods using C#

source Code:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            int[] intArray = {  1 ,  2, 3 , 4, 5 };
            Program obj = new Program();
            int[] ResultArray = obj.PassArray(intArray);

            foreach (int ArrayItem in ResultArray)
            {
                Console.Write(ArrayItem + " ");
            }
            Console.ReadLine();

        }

        private int[] PassArray(int[] tempArray)
        {
            return tempArray;
        }
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates