Anonymous Types

As their name implies, anonymous types are .NET objects that have no previously defined type in the .NET Framework or your code and can be generated on-the-fly. They were first introduced with .NET Framework 3.5, and their main purpose is collecting data from LINQ queries. You prefer named types to anonymous types outside particular LINQ scenarios; however, it’s important to understand how anonymous types work. Declaring an anonymous type is straightforward, as shown in the following code snippet:

Dim anonymous = New With {.FirstName = "Alessandro",                          .LastName = "Del Sole",                          .Email = "",                          .Age = 37}

As you can see, no name for ...

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.