The Ternary If Operator

The ternary If operator allows you to evaluate conditions on-the-fly. With this operator, you can evaluate a condition and return the desired value either in case the condition is True or if it is False. The If operator allows evaluations over three operands or two operands. Let’s start by looking at evaluations over three operands. Imagine that you have a Person class exposing both FirstName and LastName string properties and that you want to verify that an instance of the Person class is not Nothing and, subsequently, that its LastName properties are initialized. The following code shows how you can accomplish the first task (see the comments):

Sub EvaluatePerson(p As Person)    'Check if ...

Get Visual Basic 2015 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.