Saturday 16 April 2016

Write a Program to Swap 2 Nos. using Call by Value in C#.

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

namespace ConsoleApplication13
{
    class Program
    {
        static void Swap(int x, int y)
        {
            int temp;

            temp = x;
            x = y;
            y = temp;
        }

        static void Main(string[] args)
        {


           int a = 100;
           int b = 200;
           Console.WriteLine("Before swap, value of a : {0}", a);
           Console.WriteLine("Before swap, value of b : {0}", b);
Swap(a, b);

            Console.WriteLine("After swap, value of a : {0}", a);
            Console.WriteLine("After swap, value of b : {0}", b);

            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment