-10

The code is correct I checked, and there is no real problem with my PC, my hardware is a bit old but it can do the job, so I'm guessing it's the settings of Visual Studio, I use the 2017 community edition and the solution is a consol application. the solution runs but I don't see my msg or anything, just the consol opening and closing real fast

  • 2
    Could you explain better what you mean and add a question? At the moment I have no idea what you mean. Appear where? Please edit the question with more details. – Sami Kuhmonen Sep 22 '17 at 09:59
  • If you use C#, please check this tutorial: https://learn.microsoft.com/en-us/dotnet/core/tutorials/with-visual-studio – bolec_kolec Sep 22 '17 at 10:00
  • I'd guess that you don't halt the console in any way with something like `Console.ReadKey();`. Once the `Main` method ends then the console closes, this is normal. – Equalsk Sep 22 '17 at 10:19
  • Try to run without debugging, Ctrl+F5 or add `Console.ReadKey()` in the end of your main class – Markiian Benovskyi Sep 22 '17 at 10:25
  • Seems like a [duplicate](https://stackoverflow.com/q/8868338/1997232). – Sinatr Sep 22 '17 at 11:53

2 Answers2

0

check if you did everything correctly. File -> New -> New Project Visual C# on the left side, Console Application, give it a name and location.

Then write this

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

namespace Hello_world
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World");
            Console.ReadKey();
        }
    }
}

The outpot is Hello World It should stay in console and wait for pressing any button e.g.: k.

This works for my Microsoft Visual Studio Professional 2015 and I don't see a reason why it wouldn't work for you.

Štěpán Šubík
  • 109
  • 2
  • 3
  • 10
0

You are probably running the application in debug, without something to prevent it to close as soon as the job gets done.
Basically, your code executes, and the application shuts because there is nothing else left to do.
Two solutions:

  • do as Štěpán Šubík recommands : put a Console.ReadKey();
  • start the application without debugging (Ctrl+F5 or menu Debug -> Start Without Debugging).

In both case, the console won't close itself automatically :).

benichka
  • 925
  • 1
  • 11
  • 32