2

Since i know the operator ? my life changed.

Comments
  • 0
    Does the ternary operator cause you to "question" your programming choices?

    @s0LA

    It returns a value and allows assignment of the result to a variable. Quite different than if/else. Logically similar, but very handy for conditional assignments.
  • 1
    I use it to reduce lines of codes when you just need a if for 1 thing.
  • 1
    Like:

    myName = value ! = null ? value : "Unknown";
  • 0
    int i = a > 1 ? a : 1; // assigns to i

    if(a > 1) i = a; else i = 1; // i has to be explicitly assigned

    Ternary is much more convenient for short conditional assignments.
  • 0
    @s0LA My syntactic sugar is better than your syntactic sugar! 😉
  • 0
    @s0LA This is turning into a wk190 discussion.
Add Comment