【发布时间】:2013-07-02 22:15:04
【问题描述】:
在不使用本机转换函数的情况下,将 int 转换为字符串的最有效代码是什么。
public static void Main(string[] args)
{
string y = Convert(990);
Console.WriteLine(y);
Console.ReadLine();
}
public static string Convert(int x)
{
char[] Str = new char[20];
int i = 0;
while (x != 0)
{
Str[i++] = x % 10 + '0';
x = x / 10;
}
return Str.ToString();// How do I handle this without the native function?
}
以上似乎不起作用。请指教。
【问题讨论】:
-
什么?你为什么要这么做?
-
这是一项学校作业,因此不适合我们做。
-
什么可以用什么不能用?
-
虽然是一个明显的课堂或面试问题,但至少您发布了代码。另外,它给了我一个编写“聪明”代码的借口。偶尔开心。