SWAPPING PROGRAM
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SwapUsingRef
{
class swap
{
public void swapping(ref int var1, ref int var2)
{
int temp;
temp = var1;
var1 = var2;
var2 = temp;
}
}
class Program
{
static void Main(string[] args)
{
swap s = new swap();
int num1 = 5;
int num2 = 10;
Console.WriteLine(" VALUES BEFORE SWAPPING \n A={0} and B={1} ", num1, num2);
s.swapping(ref num1, ref num2);
Console.WriteLine(" VALUES AFTER SWAPPING \n A={0} and B={0} ", num1, num2);
Console.ReadLine();
}
}
}
No comments:
Post a Comment