Guest User

Guest User

  • Tech Writer
  • 357
  • 120.8k

Why doesnt this method call work?

Aug 19 2012 2:50 PM
Hi

I have the following code example:-

class Program
    {
        static void Sum(params int[] ints)
        {
            int sum = 0;

            for (int i = 0; i < ints.Length; i++)
            {
                sum += ints[i];
            }
        }
   
        static void Main()
        {
            int[] ints = { 1, 2, 3, 4 };

            Sum(ints);

            Console.WriteLine(ints);
            Console.ReadLine();
        }
   
    }

I was expecting the calling method "Main" to reflect the changes in the called method "Sum" as the array of ints is passed by reference?

Regards

Steven



Answers (2)