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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access