Explore BrainMass
Share

Explore BrainMass

    Benefits of using the C# conditional ?: (ternary) operator

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Given the expression below:

    int variable = ++d >3 ?0:d;

    What is the best way to write this as an if-else statement?? What is this code trying to do? What is good about using this approach? Why it is bad?

    © BrainMass Inc. brainmass.com October 10, 2019, 7:30 am ad1c9bdddf
    https://brainmass.com/computer-science/c-sharp/benefits-c-conditional-ternary-operator-584138

    Solution Preview

    Dear Student,
    Conditional ?: Operator implementation is attached.

    This is short and compact when handling direct value comparisons and assignments, however it is not flexible as ...

    Solution Summary

    This solution discusses on C# condition evaluation ?: statement. It shows the best way to write this as an if-else statement. It explains what the code is trying to do. What is good and bad about using this approach?

    $2.19