为什么Console.Read()不返回输入的数字? [英] Why doesn't Console.Read() return the number entered?

查看:164
本文介绍了为什么Console.Read()不返回输入的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在Visual Studio 2010 Ultimate和2008 Team System中用C#编写的程序:

this is my program that i wrote in C# in visual studio 2010 Ultimate and 2008 Team System:

class Program
{
    static void Main(string[] args)
    {
        int a=0;
        Console.WriteLine("Enter a number: ");
        a = Console.Read();
        Console.WriteLine("you Entered : {0}",a);
        Console.ReadKey();
     }
}

这是结果:

输入数字: 5 您输入的是53

Enter a number: 5 you Entered : 53

这怎么可能?

推荐答案

已转换为字符代码.试试:

Converted to a character code. Try:

a = int.Parse(Console.ReadLine());

这篇关于为什么Console.Read()不返回输入的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆