In equal comparison of a literal value does the order of operands matter?
.net, c#, performance
Solution
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 `=`:
// What you intended to write
if (a == 6) ...
// What you wrote instead
if (a = 6) ... // --> always true as the value of a is changed to 6
// What if Yoda style is used
if (6 = a) ... // --> compile time error
Problem
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