我正在运行一个非常简单的程序,只是提示用户输入一个数字,现在只需将它打印在屏幕上。但由于某些原因,我不知道,我输入数字似乎增加了数48Console.Read()不会捕获正确的信息
例如: 我进入2 和它提出了50
是否有某种根本性法律,我'监督,或某种错误的,我在我的代码做
我是初学者,如果你没有注意到
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
int Num;
Console.WriteLine("Please Input Number of Rows you want to make in your pyrimid: ");
Num = Console.Read();
Console.WriteLine(Num);// Just to check if it is getting the right number
Console.Read();//This is Here just so the console window doesn't close when the program runs
}
}
}
编辑:不想成为一个麻烦,但现在得到这个错误num = int.Parse(Console.Read());
as'int.Parse(string)'的最佳重载方法匹配有一些无效参数。这是否意味着我需要一个重载方法?
'int.Parse(INT)'读取值的ASCII值? –
Int32.Parse好像好多了! –
哦,废话!谢谢你,我应该意识到这一点!欢呼声 – user2224223