The || (or) Operator in Linq with C#

后端 未结 6 1916
独厮守ぢ
独厮守ぢ 2020-12-06 02:13

I\'m using linq to filter a selection of MessageItems. The method I\'ve written accepts a bunch of parameters that might be null. If they are null, the criteria for the file

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-06 02:36

    You are correct that the second conditional shouldn't get evaluated as you are using the short-circuit comparitors (see What is the best practice concerning C# short-circuit evaluation?), however I'd suspect that the Linq might try to optimise your query before executing it and in doing so might change the execution order.

    Wrapping the whole thing in brackets also, for me, makes for a clearer statement as the whole 'where' condition is contained within the parenthases.

提交回复
热议问题