Learn to program in Visual Basic .NET, the right way

Logic - Ternary If Statement

What is a Ternary If Statement?

The Ternary If statement is a one-liner If...Else statement.

Ternary If statements make it easier and more concise method for programmers to implement an If...Else statement.

Examples

The following demonstrates how to use a Ternary If Statement:

Fiddle: Live Demo

Remarks

Ternary If statements are extremely compact but should only be used if necessary.

I would discourage using what is called a nested Ternary If statement. This is where one or more of the values is, itself, a Ternary If statement. In these scenarios, it is best to use a traditional If statement.