-1

When I run this simple application it closes itself without reason. How to prevent that?

Code:

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);
        }
    }
}
piskot
  • 11
  • 5
  • 2
    Put `Console.ReadLine();` at the end – Equalsk Dec 08 '17 at 16:06
  • I'm guessing you mean that it closes itself when you debug it. Add a `Console.ReadLine()` at the end. – itsme86 Dec 08 '17 at 16:06
  • I already wrote the answer. –  Dec 08 '17 at 16:07
  • You need the proverbial "press any key to continue" so you can look at the console before it closes. But only when you run it in the debugger, from a desktop shortcut or Explorer. And not when you run it from the command line processor, what console mode apps were designed to do. Support either way with [this solution](https://stackoverflow.com/a/13256385/17034). – Hans Passant Dec 08 '17 at 16:15
  • thanks for answer! can you please click upvote for answer, because i dont have enough points? – piskot Dec 08 '17 at 16:21

1 Answers1

1

Just add Console.ReadKey(); after printing the value.

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();
        }
    }
}