DEV Community

Nosirbek
Nosirbek

Posted on • Edited on

5 4

C# Extension Methods

public static class MyExtensions
{
    public static int Reverse(this int num)
    {
        int result=0;

        while (num != 0) 
        {
        result = result*10 + num%10;
        num /= 10;
        }
        return result;
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        int a = -12345;

        System.Console.WriteLine(a.Reverse());
    }
}
Enter fullscreen mode Exit fullscreen mode

Result

-54321
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Sentry workshop image

Flaky tests got you down?

Learn how to merge your code without having to hit “rerun” every 5 minutes 😮‍💨

Save your spot now.

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay