I'm looking to use a single line if statement with the ?
operator to call return on a void method.
This is the full form statement:
if (failPaths.Count == paths.Count) {
return;
}
I'm aware that I could do something like if (failPaths.Count == paths.Count) return;
but I was just interested in seeing how it would be done with the ?
operator.
This can't be done using conditional operator mentioned by you as ?
operator.
In fact, conditional operator just evaluates condition and return either first or secod from two expressions - so it can be considered as expression itself.
But in your example if
statement is used not for expression evaluation, but for control flow.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With