Array Literals

Visual Basic 2010 introduces a new feature known as array literals. Basically it works like the local type inference but it is specific to arrays. For example, consider this array of strings declaration as you would write it in Visual Basic 2008:

Dim anArrayOfStrings() As String = {"One", "Two", "Three"}

Now in Visual Basic 2010 you can simply write it as follows:

'The compiler infers String() Dim anArrayOfStrings = {"One", "Two", "Three"}

According to the preceding code, you are still required to only place a couple of parentheses, but you can omit the type that is correctly inferred by the compiler as you can easily verify by passing the mouse pointer over the variable declaration. Of course, array literals work also with value ...

Get Visual Basic® 2010 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.