in vb.net it is end
what is the best way to end a program in c#?
in vb.net it is end
what is the best way to end a program in c#?
Application.Exit();
This is the nice way to ensure all Forms are closed and the application shuts down in a controlled way. From MSDN:
Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.
If this is a console app, use:
Environment.Exit(0);
The best way to exit a program in any language is to naturally hit the end of the programs execution.
In other words. The best way to exit a C# program is to exit the Main
method naturally. This will ensure that all resources get cleaned up properly, and it is much easier to follow a program that does exit in the middle of the code.
It depends on the type of application.
I'll give it a shot:
}
Seriously, most well written programs end naturally when the main function ends. You achieve this with careful flow control like break
.
try
{
int i = 1/0;
}
catch (Exception e)
{
Console.WriteLine("Press any key to continue ...");
}
finally
{
Console.ReadLine();
}