No, switch statements/expressions are about evaluating a single expression, then testing it against multiple values/patterns. It sounds like you want to evaluate multiple expressions, checking each against the same value (null).
Without knowing more details (like whether or not you'd actually want to execute multiple methods if multiple properties are null) it's hard to recommend a specific pattern, but switch almost certainly isn't a good fit.
It's just possible that pattern matching would actually allow this:
You are able to use a switch case for checking null values, but it would have to be on each individual property, but for a switch statement you can do:
发布评论
评论(2)
不,开关语句/表达式是关于评估单个表达式,然后针对多个值/模式进行测试。听起来您想评估多个表达式,对每个表达式进行检查,以相同的值(NULL)检查。
在不知道更多细节的情况下(例如,如果多个属性为null,您是否真的想执行多种方法),很难推荐特定模式,但是
switch> switch
几乎可以肯定并不适合。这只是可能的 ,模式匹配实际上允许这样做:
...但是与惯用的C#相去甚远,我真的不会做。
No, switch statements/expressions are about evaluating a single expression, then testing it against multiple values/patterns. It sounds like you want to evaluate multiple expressions, checking each against the same value (null).
Without knowing more details (like whether or not you'd actually want to execute multiple methods if multiple properties are null) it's hard to recommend a specific pattern, but
switch
almost certainly isn't a good fit.It's just possible that pattern matching would actually allow this:
... but that's so far from idiomatic C# that I really wouldn't do it.
您可以使用开关案例来检查空值,但是它必须在每个单独的属性上,但是对于Switch语句,您可以执行:
You are able to use a switch case for checking null values, but it would have to be on each individual property, but for a switch statement you can do: