The Null-Propagating Operator and Value Types
Chapter 4, “Data Types and Expressions,” introduced the null-propagating operator and you saw how you can use it against reference types to check whether an object is null before you use it. With value types, things are different. In fact, as you may recall, value types do not return Nothing
but instead return a default value. For instance, the default value for the Integer
type is 0
. For this reason, you do not need to use the null-propagating operator against a value type directly. However, the null-propagating operator is very useful when you want to check whether an object exposing a property as a value type is not null. To better understand this, consider the following Person
class, which exposes ...
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.