DEV Community

Nosirbek
Nosirbek

Posted on • Updated on

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)