HomeCSharpFinding the Reverse of a Number in C# using Extension Methods

Finding the Reverse of a Number in C# using Extension Methods

If you are looking forward to find the reverse of a number in C# , below is a sample source code that demonstrates how to do it using extension methods in c#.

Finding the Reverse of a Number in C# using Extension Methods

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

namespace GinktageConsoleApp
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            int input = 4761;

            Console.WriteLine(input.Reverse()); ;
            Console.ReadLine();
        }
    }
    public static class Helper
    {
        public static int Reverse(this int value)
        {
            int retValue = value;
            int OutPut = 0;
            while (retValue > 0)
            {
                int rem = retValue % 10;
                OutPut = (OutPut * 10) + rem;
                retValue = retValue / 10;
            }
            return OutPut;
        }
    }

    
}

Leave a Reply

You May Also Like

This C# program calculates and displays an upper triangular matrix based on user input. Problem Statement: The program takes the...
This C# program serves as a demonstration of bitwise operators, which are fundamental operators used for manipulating individual bits in...
This C# program is designed to interchange or swap the columns of a matrix. A matrix is a two-dimensional array...