C# Program to swap two numbers


This program in C# developed using .NET Framework and Visual Studio  will demonstrate how to swap numbers using the temporary variable.

C# Program to swap two numbers

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

namespace GinktageConsoleApp
    internal class Program
        private static void Main(string[] args)
            int Input1, Input2, tempNumber;

            Console.Write("Input the First Number ");

            Input1 = int.Parse(Console.ReadLine());

            Console.Write("\nInput the Second Number : ");

            Input2 = int.Parse(Console.ReadLine());

            tempNumber = Input1;

            Input1 = Input2;

            Input2 = tempNumber;

            Console.Write("\nResult after Swapping the two number : ");

            Console.Write("\nFirst Number : " + Input1);

            Console.Write("\nSecond Number : " + Input2);



If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Reply


Interesting BlogPosts to read

How to add entries to ResourceDirectory in WPF using C# ?
Below is a sample code snippet demonstrating how the entries can be added to the ResourceDirectory i...
Replacing Multiple spaces with single space in C#
Are you looking at an sample demonstrating the usage of the regular expression to replace multiple s...
How to rename a file in C# ?
Want to rename a file using .NET Framework and C# ? , below is a sample code snippet that illustrate...