How do I exit the program?

  • Thread starter Thread starter Amanda
  • Start date Start date
A

Amanda

(1) What code should I put in case 'e':?
(2) Should I still put default case?


do
{
Console.Write("Enter a selection from the following
list:\n" +
"a. Display ...................\n" +
"b. Display ....................\n." +
"c. Display ................\n.." +
"e. Exit this program\n");


ch = Char.Parse(Console.ReadLine());
Console.WriteLine("");


switch (ch)
{

case 'e':
????????

} // end switch


} while ( ch== etc.)
 
Uzytkownik "Amanda said:
(1) What code should I put in case 'e':?
(2) Should I still put default case?


do
{
Console.Write("Enter a selection from the following
list:\n" +
"a. Display ...................\n" +
"b. Display ....................\n." +
"c. Display ................\n.." +
"e. Exit this program\n");


ch = Char.Parse(Console.ReadLine());
Console.WriteLine("");


switch (ch)
{

case 'e':
????????

} // end switch


} while ( ch== etc.)

Try this one. Add reference System.Windows.Forms in to your project and then
you can use Application.Exit()

Forrest
 
Forrest said:
Uzytkownik "Amanda said:
(1) What code should I put in case 'e':? [..]

Try this one. Add reference System.Windows.Forms in to your project and then
you can use Application.Exit()

This is Console application as required by sample exe file given.
 
Amanda said:
(1) What code should I put in case 'e':?
(2) Should I still put default case?


do
{
Console.Write("Enter a selection from the following
list:\n" +
"a. Display ...................\n" +
"b. Display ....................\n." +
"c. Display ................\n.." +
"e. Exit this program\n");


ch = Char.Parse(Console.ReadLine());
Console.WriteLine("");


switch (ch)
{

case 'e':
????????

} // end switch


} while ( ch== etc.)

Enviroment.Exit(int n);

n is errorcode returned to os.
 
(1):
return;

or

break;

depending on the context of the loop.

or {} and then in the contidition: ch != 'e';

(2):
Maybe prompt some error message;
what does the sample exe do?
 
Christof said:
(1):
return;

or

break;

depending on the context of the loop.

I tried break before my initial post - it didn't work - but return
does. Thnaks.
or {} and then in the contidition: ch != 'e';

(2):
Maybe prompt some error message;
what does the sample exe do?

It says "Press any key to continue..."
 
Back
Top