我想从键盘接收一个int型参数,我是这样写的:
using system;
class myclass
{
static void Main()
{
int x=Console.ReadLine();
}
}
但是编译器说我 Can't not convert string to int。
我刚学C#,问个笑话的问题。不过照样给分。
...全文
1559打赏收藏
怎样接收键盘输入阿?
我想从键盘接收一个int型参数,我是这样写的: using system; class myclass { static void Main() { int x=Console.ReadLine(); } } 但是编译器说我 Can't not convert string to int。 我刚学C#,问个笑话的问题。不过照样给分。
还是使用ReadLine吧.
static void Main() {
int x=0;
int y=0;
Console.WriteLine("Now, please input the x value: ");
x=Console.ReadLine().ToInt32();
Console.WriteLine("x={0}",x);
Console.WriteLine("Now, please input the y value: ");
y=Console.ReadLine().ToInt32();
Console.WriteLine("y={0}",y);
Console.ReadLine();
}