C# Program to Swap Two Numbers Using Methods

Below is the program for swapping of two numbers using methods and classes. You need to make objects for the progarm to execute…Here is the program:-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
    public class swapnumber
        void swapnum(ref int a,ref int b)
        int temp;
        static void Main (string[] args)
            swapnumber classobj= new swapnumber();
            int number1,number2;
            Console.WriteLine(“enter the two no.”);
            Console.WriteLine(“Value of first number is :” + number1);
            Console.WriteLine(“THe value of second number is ” + number2);
            classobj.swapnum(ref number1,ref number2);
            Console.WriteLine(“Now the value of first number after swap is: “+ number1);
            Console.WriteLine(“Now the value of second number after swap is: “+ number2);

The following program is tested in Microsoft Visual basic 2008 and is running currently…..

Add Comment