Many times in programming you want to set the contents of a variable to one value if the condition is true, or to another value if the condition if false. For example, consider the following code. string status; if (qty > 0) status = "Available"; else status = "Unavailable"; Notice that status could be available or unavailable depending on the value of qty. In C# these five lines of code can be condensed into a single line of code using the conditional operator (? :) . To use the conditional operator:
Tip
|