+ 5

My program does not work without Console.ReadKey() Why?

27th Jun 2019, 10:56 AM
Ицо Христов
Ицо Христов - avatar
6 ответов
+ 1
How can I understand? At least write a little of your code.
27th Jun 2019, 1:14 PM
ΛM!N
ΛM!N - avatar
+ 3
I use visual studio. I leave the program by default with the start Console.WriteLine("Hello World"); but there is a line right below hello world which says Console.ReadKey();.When i delete this line of code the program starts and stop immediately.
28th Jun 2019, 6:46 AM
Ицо Христов
Ицо Христов - avatar
+ 3
That happens because the program has finished execution. The readkey function allows the program to wait for user input to complete execution
30th Jun 2019, 11:36 AM
Masterjoe
Masterjoe - avatar
+ 2
Do you use the playground or visual Studio. Can you share the code ? What happens if you do not use Console.ReadKey() ?
27th Jun 2019, 1:49 PM
sneeze
sneeze - avatar
+ 2
This is correct behaviour. When the program finishes, it closes the window. The computer cannot determine if you have read the result. So adding a additionel Console.ReadKey() is totally legal. Run the code with ctrl-F5 Will also do the trick
28th Jun 2019, 7:25 PM
sneeze
sneeze - avatar
+ 1
when you dont use from console.readkey your program start working and after 1 second closing in consoleapplications its for { to mean start and } meaning close
27th Sep 2019, 8:41 PM
amirhosein.dev
amirhosein.dev - avatar