WebJan 17, 2016 · you can put you code in a try catch block and do whatever you want to do in the finally block without worrying about the exception. try { //try something } catch (Exception ex) { //catch all exceptions and log on need basis //but do not throw the exception from here } finally { return "Test"; //do what ever you want to do } Share Webpublic void SomeFunction (bool someCondition) { if (!someCondition) return; // Do Something } I usually code with the first one since that is the way my brain works while coding, although I think I prefer the 2nd one since it takes care of any error handling right away and I find it easier to read coding-style control-structures Share
c# - How to exit method from sub-method without throwing exception ...
WebSep 30, 2008 · There are three methods that you can use to return an exit code from a console application. Modify the Main method in your application so that it returns an int instead of void (a function that returns an Integer instead of Sub in VB.NET) and then return the exit code from that method.; Set the Environment.ExitCode property to the exit … WebOct 4, 2024 · The docs tell us that “If the method is a void type, the return statement can be omitted.”; this means that we can leave a function (i.e. return from a function) without … ram setu trailer download
Jump statements - break, continue, return, and goto
WebApr 28, 2012 · where ConfirmFormExit () is a bool function showing a MessageBox asking user if he wants to quit without submitting and returns true on Yes . Thus, the code will be : private void btnSubmit_Click (object sender, EventArgs e) { // avoid form exit right now this.DialogResult = DialogResult.None; // ask user if he wants to fill the comment : if so ... WebMar 3, 2024 · foreach (string s in sList) { if (s.equals ("ok")) return true; } return false; Alternatively, if you need to do some other things after you've found the item: bool found = false; foreach (string s in sList) { if (s.equals ("ok")) { found = true; break; // get out of the loop } } // do stuff return found; Share Improve this answer WebThere are two possibilities: (1) move that code into the main method (there's no reason for it to be in its own function), (2) change that function to return a value—either false to close, or an int that corresponds to the return value from main. Check the result of that function inside of your main method and return accordingly. – Cody Gray ♦ overnight customer service work from home