|
-
Jul 7th, 2006, 11:33 AM
#1
Thread Starter
Hyperactive Member
[2.0] How to do a clean exit from console application.
Based on the result of my checking, I would like to exit out from the console application decently without throwing any exceptions.
static void Main(string[] args)
{
//Check to see if today is a US Holiday.
If(Holiday.IsUSHoliday(DateTime.Today));
//close the program and how to do that?
}
-
Jul 7th, 2006, 11:35 AM
#2
Re: [2.0] How to do a clean exit from console application.
-
Jul 7th, 2006, 03:04 PM
#3
Re: [2.0] How to do a clean exit from console application.
 Originally Posted by mendhak
Try:
return;
it works in C, C++, Java and I bit it'd work in C#
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 9th, 2006, 01:35 AM
#4
Re: [2.0] How to do a clean exit from console application.
Using the return keyword anywhere except for the last line of a procedure is spaghetti code. You should structure your if{} blocks in a manner such that if the condition arises where the application should exit, the code path naturally jumps to the end of the Main() procedure.
For example:
Code:
// Bad:
static void Main(string[] args)
{
if (Holiday.IsUSHoliday(DateTime.Today)) {
return;
}
// rest of code
}
// Good:
static void Main(string[] args)
{
if (!Holiday.IsUSHoliday(DateTime.Today)) {
// rest of code
}
}
-
Jul 11th, 2006, 03:12 PM
#5
Re: [2.0] How to do a clean exit from console application.
 Originally Posted by penagate
Using the return keyword anywhere except for the last line of a procedure is spaghetti code.
Does this mean that Italians aren't very good coders?
-
Jul 12th, 2006, 02:56 AM
#6
Re: [2.0] How to do a clean exit from console application.
you could just use
Code:
Environment.Exit(0);
when you want to exit from the program. more info on msdn.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|