Saturday, 25 May 2013

C# Console Program to Pass as Reference Variable


Simple Program to Pass as Reference Variable

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

 

namespace pararef

{

    class Program

    {

        static void Main(string[] args)

        {

            int a=10 , b=20;//actual var

            Console.WriteLine("A=" + a + " B=" + b);

            swap(ref a, ref b);

            Console.WriteLine("A=" + a + " B=" + b);

        }

 

        private static void swap( ref int x,ref int y) //reff var

        {

            int z;

            z = x;

            x = y;

            y = z;

            Console.WriteLine("X=" + x + " Y=" + y);

 

        }

    }

}

No comments:

Post a Comment