Switch case where linq condition

how can I use the switch case in where, where is the sentence, and also the select statement can give me examples ...

+3
source share
1 answer

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

You can invest them, it will be a little dirty, but it should work.

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

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

+7
source

All Articles