using System;
class Program
{
static void Main(string[] args)
{
Console.Write(20);
int myAge = Console.Read() + 10;
Console.WriteLine(myAge);
}
}
打印20它挂出来,没有打印:(
using System;
class Program
{
static void Main(string[] args)
{
Console.Write(20);
int myAge = Console.Read() + 10;
Console.WriteLine(myAge);
}
}
打印20它挂出来,没有打印:(
Console.Write(20);
int myAge = int.Parse(Console.ReadLine()) + 10;
Console.WriteLine(myAge);
代码等待你inpu有些事情。
这是为什么降低了投票率? – 2010-11-22 20:42:45
Console.Read()正在等待你输入的东西,这就是为什么它后停止后它打印出20
。尝试输入的东西,然后按回车
您应该改用ReadLine()。
Console.Write(20);
string line = Console.ReadLine();
int number, myAge = 0;
if (int.TryParse(line, out number))
myAge = number + 10;
Console.WriteLine(myAge);
你在控制台上输入什么东西?当您输入输入字符时,Read方法阻止它的返回;它会在您按Enter键时终止。http://msdn.microsoft.com/en-us/library/system.console.read.aspx – dsolimano 2010-11-22 20:38:07
怎么了格式化?代码块似乎不工作! – 2010-11-22 20:39:28