| operator operation in linq?
|(pipe) operator in linq?i want to know operation of operator(|).i want to check multiple columns in different table.In my scenario only single table contain value for that perticular column.
my code:
&& swr.Date_Of_Event.Date < DateTime.Toda开发者_C百科y.Date |
spr.Date_Of_Event.Date < DateTime.Today.Date |
scr.Date_Of_Event.Date < DateTime.Today.Date |
smr.Date_Of_Event.Date < DateTime.Today.Date
In this scenario only one table will contain date value others will contain dault values in their respected columns.
The above condition is not working,it takes default value.
what condition can i use to get correct value?
The |
operator gives the same result as the ||
operator, but it's not short-circuiting the result. That means that both operands are always evaluated even if the result can be determined by evaluating only the first operand.
I think that the main problem is that the &&
operator has higher precedence than the |
operator (or the ||
operator), so you need parentheses:
&& (swr.Date_Of_Event.Date < DateTime.Today.Date |
spr.Date_Of_Event.Date < DateTime.Today.Date |
scr.Date_Of_Event.Date < DateTime.Today.Date |
smr.Date_Of_Event.Date < DateTime.Today.Date)
You can use the short-circuiting version of the operator instead, as reading the Date
properties doesn't have any side effects:
&& (swr.Date_Of_Event.Date < DateTime.Today.Date ||
spr.Date_Of_Event.Date < DateTime.Today.Date ||
scr.Date_Of_Event.Date < DateTime.Today.Date ||
smr.Date_Of_Event.Date < DateTime.Today.Date)
Do you mean to use ||
instead? they look like "or" constraints to me... also, when mixing &&
and ||
, be very clear with brackets... i.e. is it (x && y) || z
, or x && (y || z)
I think you need to replace | with || and you probably want to put those four condition in parenthesis after the && operator. Like this:
&& (swr.Date_Of_Event.Date < DateTime.Today.Date ||
spr.Date_Of_Event.Date < DateTime.Today.Date ||
scr.Date_Of_Event.Date < DateTime.Today.Date ||
smr.Date_Of_Event.Date < DateTime.Today.Date)
精彩评论