开发者

switch case in where clause of linq

how i can us开发者_如何学Ce switch case in where clause as well as select statement can anyone give me examples...


You can not use switch, you need a construct that returns a value (switch does not return a value in c#), like the ternary operator <cond> ? <trueValue> : <falseValue>.

You can nest them, it will be a bit messy, but should work.

cond1 ? valueFor1 :
       (cond2 ? valueFor2 : 
               (cond3 ? valueFor3 : 
                        defaultValue))

but in the where-clause it is usually simpler to combine your conditions with && and ||.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜