I am accustomed to write the code as(just an example)
Request.QueryString["xxxx"] != null
Recently someone said that
null != Request.QueryString["xxxx"]
gives a better performance.
I am curious to know as whether it actually brings any difference or not and if so how?
Note~ The above is just an example. To be generically speaking
Whether
Constant [Operator] Actual Value (e.g. 1 == Convert.ToInt32(textbox1.text))
is better than
Actual Value [Operator] Constant (e.g. Convert.ToInt32(textbox1.text) == 1)
Thanks
No, it’s not true in general. Comparison operators need to evaluate both their sides so there is no gain in putting constants on the left. But having them on the left hand side (called Yoda style) reduces coding errors in languages where you are allowed to use assignment operator inside a conditional and you unintentionally mistyped the comparison operator
==as a single=: