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 ||
.
精彩评论