This subject has been discussed many times and is clear: Is relying on && short-circuiting safe in .NET?
What I cannot find is a clear answer if the short circuit is also reliable when out
parameter is used in the right part of the if
clause:
int foo;
....
if ( false == Int32.TryParse( bar, out foo ) || 0 == foo )
When I try this code then it works. But I am just a bit worried if the behavior is reliable, because I don't know how the compiler is translating the code and accessing foo
.
My question:
Is the access to foo
really done after the TryParse
which would consider any changed value or the compiler can sometimes read the value before TryParse
[because of some optimizations] and therefore I cannot rely on this code.