为什么要加这么一句?
大家好!我是一个V#的初学者,现在正在拜读周靖老师翻译的《Visual c#2010从入门到精通》这本书,其中一个例子让我这个门外汉有点匪夷所思,例子如下:十进制转成八进制
private void showStepsClick(object sender, RoutedEventArgs e)
{
int amount = int.Parse(number.Text);
steps.Text = "";
string current = "";
do
{
int nextDigit = amount % 8;
amount /= 8;
int digitCode = '0' + nextDigit;
char digit = Convert.ToChar(digitCode);
current = digit + current;
steps.Text += current + "\n";
}
while (amount != 0);
}
让我匪夷所思的是这两句:
int digitCode = '0' + nextDigit;
char digit = Convert.ToChar(digitCode);
后来我自己修改了一下,调试后一切正常:
private void showStepsClick(object sender, RoutedEventArgs e)
{
int amount = int.Parse(number.Text);
steps.Text = "";
string current = "";
do
{
int nextDigit = amount % 8;
amount /= 8;
string digit = nextDigit.ToString();
current = digit + current;
steps.Text += current + "\n";
}
while (amount != 0);
}
请大家给我一个提示,为什么一定要加这两句,谢谢!