Background:
Yesterday a friend went out to interview and encountered the question: "C # catch there return." Finally also get it run? ”
Personal Summary Practice:
1, whether there is an abnormal wood. The code in the finally block will run .
2. finally will still run when there is a return in the try and catch .
The detailed case ratio is as follows (this is verified with a function with no return value):
3, Assuming that the value is passed. The value changed in finally has no effect on the value returned by return in the try or catch block . The assumption is that reference type parameters (address passing or object), and the value change in finally will have an effect on return .
Detailed case:
Reference case--array type:
Value Case--int Type:
Thinking: String types are reference types. So is the return value affected by finflly? Let's take a look at the case.-----In fact, the string behaves like the int type without being affected by finally:
Think: So what's the effect of adding return to finally? There is a picture of the truth:
Visible. Finally, the return is not agreed. Or you can't even compile.
Copyright notice: Author: jiankunking Resources: http://blog.csdn.net/jiankunking This document is copyrighted to the author and csdn partner, welcome reprint, however, if not announced from this section the permissions must be retained. and connect to the original article page to give a view of the location.
Have return if it is a try Catch finally Run command