显示结果前控制台关闭

时间:2018-11-22 18:38:49

标签: c# console

using System;
public class Exercise6
{
    public static void Main()
    {

    int x,y,z;

    Console.Write("First number:");
    x = Convert.ToInt32(Console.ReadLine());

    Console.Write("\nSecond number:");
    y = Convert.ToInt32(Console.ReadLine());

    Console.Write("\nThird number:");
    z = Convert.ToInt32(Console.ReadLine());

    int res1 = ((x + y) * z);
    Console.WriteLine(res1);
}

}

因此,我希望它在控制台上显示“ res1”,但它只是关闭。如何停止关闭控制台?

1 个答案:

答案 0 :(得分:0)

如果您向Console.ReadLine()添加另一个调用,则控制台窗口将保持打开状态,直到您按下Enter键为止。

using System;
public class Exercise6
{
    public static void Main()
    {

    int x,y,z;

    Console.Write("First number:");
    x = Convert.ToInt32(Console.ReadLine());

    Console.Write("\nSecond number:");
    y = Convert.ToInt32(Console.ReadLine());

    Console.Write("\nThird number:");
    z = Convert.ToInt32(Console.ReadLine());

    int res1 = ((x + y) * z);
    Console.WriteLine(res1);
    Console.ReadLine();
}