+ 5
My program does not work without Console.ReadKey() Why?
6 odpowiedzi
+ 1
How can I understand? At least write a little of your code.
+ 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.
+ 3
That happens because the program has finished execution. The readkey function allows the program to wait for user input to complete execution
+ 2
Do you use the playground or visual Studio. Can you share the code ?
What happens if you do not use Console.ReadKey() ?
+ 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
+ 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