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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay