Convert the following int argument into a string without using any native toString functionality.
public string integerToString(int integerPas
Aiming for a shorter version, and one that uses Math.DivRem:
string IntToString(int a)
{
if (a == int.MinValue)
return "-2147483648";
if (a < 0)
return "-" + IntToString(-a);
if (a == 0)
return "0";
var s = "";
do
{
int r;
a = Math.DivRem(a, 10, out r);
s = new string((char)(r + (int)'0'), 1) + s;
}
while (a > 0);
return s;
}
The use of the new string(..., 1) constructor is just a way to satisfy the OP's requirement that ToString not be called on anything.