how to stop the console application during execution through taking any specific input from user like if we ask him that press Y to exit.
Asked
Active
Viewed 438 times
-3
-
2http://stackoverflow.com/questions/10286056/what-is-the-command-for-exit-an-console-application-on-c – MrVimes Jan 25 '14 at 16:18
-
Pretty unclear why your user needs help to exit your program. He can press Ctrl+C or click the close button. Bam, gone. No point in giving him a 3rd option and forcing him to type N repeatedly. – Hans Passant Jan 25 '14 at 16:30
-
dear problem is solved now.. and think why the 3rd way is created that i found... these are created to use – Syed Jan 25 '14 at 16:36
2 Answers
3
Try This:
Console.WriteLine("Enter Y to Exit");
String strInput=Console.ReadLine();
if(strInput.Equals("Y"))
{
Environment.Exit(0);
}

Sudhakar Tillapudi
- 25,935
- 5
- 37
- 67
0
You probably have to look in the direction of Console.ReadKey()
. This will block the executing thread until input has been received.
For more information see this page: http://msdn.microsoft.com/en-us/library/471w8d85%28v=vs.110%29.aspx

Raxr
- 965
- 7
- 12
-
`Console.KeyAvailable` MSDN help already contains an example http://msdn.microsoft.com/en-us/library/system.console.keyavailable(v=vs.100).aspx – Max Yakimets Jan 25 '14 at 16:23