-2

How to exit a method, instead of raise new Exception or return in console application.

if (!String.IsNullOrEmpty(args[i + 1].ToString()))
{
    inputFilePath = args[i + 1].ToString();
}
else
{
   //code to exit console application run
}
Rollend Xavier
  • 572
  • 4
  • 18
  • Why would you want to do it any other way – Tim Oct 31 '14 at 09:18
  • 1
    not sure what you want, Application.Exit will stop your program straight away (as said above). However: if you start your application inside a console and you exit, you will return to the console (so the black screen with the text will remain). That is simply how windows work and you can't change that. – Nick Otten Oct 31 '14 at 09:43

1 Answers1

1

If you are trying to exit your program do return if you want to return an exit status (as this SO answer says) make your main's return type int and return an int.

Community
  • 1
  • 1
AlG
  • 14,697
  • 4
  • 41
  • 54