Object Initializers

Object initializers enable inline initialization of objects’ members when creating an instance, without the need of providing specific constructors’ overloads. For a better understanding, let’s provide a practical example. The Contact class could be implemented without a constructor overload that receives any arguments for initialization:

Public Class Contact    Public Property FirstName As String    Public Property LastName As String    Public Property Email As String    Public Property Address As StringEnd Class

To instantiate the class and initialize its members, according to the classical, old-fashioned syntax, you should write the following code:

Dim aContact ...

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.