C# Extension Methods

xakimov_dev

Nosirbek

Posted on May 9, 2022

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
💖 💪 🙅 🚩
xakimov_dev
Nosirbek

Posted on May 9, 2022

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related