I came across a question \"How can one reverse a number as an integer and not as a string?\" Could anyone please help me to find out the answer? Reversal should reverse the
a new one:
using System;
using System.Linq;
public class Program
{
public static void Main()
{
int i = 234;
int j = -123;
Console.WriteLine(reverse(i));
Console.WriteLine(reverse(j));
}
static int reverse(int i)
{
int sign = i / Math.Abs(i);
var abs = string.Concat(Math.Abs(i).ToString().Reverse());
return int.Parse(abs) * sign;
}
}
https://dotnetfiddle.net/VGJJFf