运行后,C#console app自行关闭

时间:2017-12-08 16:05:38

标签: c# console-application

当我运行这个简单的应用程序时,它无缘无故地关闭。如何防止?

代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 20;
            int c = a * b;

            Console.WriteLine(c);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

打印值后,只需添加Console.ReadKey();即可。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 10;
            int b = 20;
            int c = a * b;

            Console.WriteLine(c);
            Console.ReadKey();
        }
    }
}