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 the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.