perform swapping in C#

Posted by Raj_Chennai under C# category on | Points: 40 | Views : 2334
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace swaping
class Program

void swapNum(ref int a,ref int b)
int temp;
static void Main(string[] args)
Program num = new Program();
int number1, number2;
Console.WriteLine("enter the first no");
number1 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("enter the second no");
number2 = Convert.ToInt16(Console.ReadLine());
Console.WriteLine("**********The value before swapping*********** ");
Console.WriteLine("the value of first no is{0}", number1);
Console.WriteLine("the value of second no is{0}", number2);
num.swapNum(ref number1, ref number2);
Console.WriteLine("**********The value after swapping**********");
Console.WriteLine("the value after swapping is{0}", number1);
Console.WriteLine("the value after swapping is{0}", number2);


Comments or Responses

Posted by: Shubham on: 3/10/2012 Level:Starter | Status: [Member] | Points: 10
dear in this code what is the use of linq namespace??
and why we use three variable....

try this ::::
int a=10;
int b=12;
this code are swap numbers so why use third variable thanks....
tag ur ans.....

Posted by: Raj_Chennai on: 3/12/2012 Level:Starter | Status: [Member] | Points: 10
just remove the namespace "Using system.LINQ" then all code will work.The code which i shared is in visualstudio2010 so by default it provide this namespace.I have the requirement to use temp variable to store the variable so used to store in it

Login to post response