We're going to go over some syntax that are used for a number of reasons:
var
keyword is considered best practice.CCR: an acronym that stands for Clear, Concise, Readable:
Inline If is syntax sugar. Remember the almighty if? Well it was only a matter of time before someone thought that 2 characters was too much to type.
An inline if (also called a ternary operator) has a few parts, following this format:
(conditional) ? true-scope : false-scope;
Option 1: Normal if statement
int i = 1;
String positiveMessage = "You're not positive. Hmm...";
if (i > 0)
{
positiveMessage = "You are positive!";
}
Option 2: Inline If/Ternary Operator
int i = 1;
String positiveMessage = (i > 0) ? "You are positive!" : "You're not positive. Hmm...";
Option 2 is clear and readable, like Option 1, yet Option 2 is far more concise.