Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#控制台程序问题_C#_C# 4.0_Console - Fatal编程技术网

C#控制台程序问题

C#控制台程序问题,c#,c#-4.0,console,C#,C# 4.0,Console,我需要帮助理解这个简单的C#控制台应用程序可能有什么问题。我想做的是通过类执行各种算术运算。这是节目单 static void Main(string[] args) { Console.Clear(); Arithmetic a1 = new Arithmetic(); Console.Write("\nEnter the value for first variable\n"); a1.obj1 = Console.Re

我需要帮助理解这个简单的C#控制台应用程序可能有什么问题。我想做的是通过类执行各种算术运算。这是节目单

static void Main(string[] args)
    {
        Console.Clear();
        Arithmetic a1 = new Arithmetic();
        Console.Write("\nEnter the value for first variable\n");
        a1.obj1 = Console.Read();
        Console.Write("\nEnter the value for the second variable\n");
        a1.obj2 = Console.Read();

        Console.WriteLine("Press any key to exit");

        Console.ReadKey();
    }
显然,该程序构建和编译正常,但在运行时它取第一个整数的值,而不取下一个整数的值,它会在显示器上写入最后一行(按任意键退出)

Console.Read()
从标准输入读取单个字符,并返回其ASCII值。
如果按两个键,每个
Console.Read()
调用将返回其中一个

您可能需要
ReadLine()
,它读取整行文本(然后您需要将其解析为
int