This will throw a null reference exception when InnerException is null.
String s = " inner exception: " + e.InnerException == null ? "None" : e.InnerException.Message;
but this won’t:
String s = " inner exception: " + (e.InnerException == null ? "None" : e.InnerException.Message);
Both of the above build fine. I can’t figure out what the former is trying to do that would cause it to evaluate e.InnerException.Message. Why aren’t they equivalent?
This is because your first statement is evaluating
" inner exception: " + e.InnerException == nullto betrueorfalse. It’s all about operator precedence, which is why the second works just fine due to the parenthesis ((and)).See this reference for Operator Precedence. The
+operator is evaluated before the equality==operator.