Friday, 1 September 2017

C# programming to demonstrate use of pass by reference

C# program example to use of pass by reference in C# program

Program

using System;
class Program
    {
        static void Main(string[] args)
        {
            int a = 5, b = 6;
             swap(ref a, ref b);
        }
        public static void swap(ref int x, ref int y)
        {
            int z;
            z = x;
             x = y;
             y = z;
            Console.WriteLine("a: {0}  b:{1}", x, y);
        }

     } 

Output


0 comments:

Post a Comment