using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace passbyreference { class PassByRef { static double Average(int a, int b) { double ave; Console.WriteLine("Beginning of method Average: a={0}, b={1}", a, b); a = a + b; ave = a / 2.0; Console.WriteLine("End of method Average: a={0}, b={1}", a, b); return ave; } static double AverageRef(ref int a, int b) { double ave; Console.WriteLine("Beginning of method Average: a={0}, b={1}", a, b); a = a + b; ave = a / 2.0; Console.WriteLine("End of method Average: a={0}, b={1}", a, b); return ave; } static void FunctionOutRef(ref int c, out int d) { d = c + 1; c = c + 1; } static void Main(string[] args) { int num1, num2; Console.WriteLine("Enter two integers: "); num1 = Convert.ToInt32(Console.ReadLine()); num2 = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("In Main before calling average: num1={0}, num2={1}", num1, num2); double average = Average(num1, num2); // double average = AverageRef(ref num1, num2); Console.WriteLine("In Main average={0}", average); Console.WriteLine("In Main after calling average: num1={0}, num2={1}", num1, num2); int num3 = 5, num4; FunctionOutRef(ref num3, out num4); } } }