I created the Microsoft Visual Studio 2012 console application. This is what I added to my code.
static void Main(string[] args) { Console.WriteLine("Hello World"); }
When I debug this program, the program immediately closes! What am I doing wrong?
You must add Console.ReadLine()at the end of the method Main, this will make the console wait until the user sends any input to the console, and then it exits.
Console.ReadLine()
Main
Al existing answers are correct, but Ctrl-F5 (and not just F5 in VS) will also have the effect of waiting for a keystroke to start.
EDIT
, . F10 .
Console.WriteLine("Hello World"); Console.ReadLine();
, , , . Console.ReadLine , , . Enter.
ReadKey, : " , ..." , , .
static void Main(string[] args) { Console.WriteLine("Hello World"); Console.Read(); }
Console.ReadLine(); WriteLine, . .
Console.ReadLine();
WriteLine
static void Main(string[] args) { Console.WriteLine("Hello World"); Console.ReadLine(); }
You can just add
Console.ReadKey();
This will wait for the key to be pressed before closing the program.
all of the above is correct. Typically, Console.ReadKey () is used for control instead of logical processing.
static void Main(string[] args) { Console.WriteLine("Hello World"); string line = Console.ReadKey(); }
you can get more information here
Source: https://habr.com/ru/post/1542290/More articles:Applescript Execute Shell with login and administrator privileges - bashAngular событие щелчка дротика наhref, которое завернуто в теневое dom, перенацелено в оболочку - dartHow to bind events to methods using Autofac? - c #Java 8 functionality: how to calculate a list of dependent object evolutions? - javaHow to view Jenkins server console output on local file system? - jenkinsMaximum concurrent connections for MySQL - mysqlScanf in several larynx gives unexpected results - goIn a large dataset, determine which variables are categorical and which are numeric - rWhy does the TypeFormatter web API not start in the same Call Context as the request request? - c #Не удалось выложить большую память блока после того, как много памяти malloc/free small blocks - c++All Articles