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

Your email address will not be published. Required fields are marked *

You May Also Like

C# Compiler Error CS0442 – ‘Property’: abstract properties cannot have private accessors Reason for the Error You’ll get this error...
This is a really simple one . Below is a simple example of an enum called “Designation” defined with the...
This blog post explain the usage of the Checked Block in .NET and how you can use them in Visual...