|
Visual Basic 2010 array litererals provide a shortcut mechanism for declaring and filling arrays for types that can be inferred by the compiler. Here a three examples:
' Examples
Dim a = {1, 2, 3} 'infers Integer()
Dim b = {1, 2, 3.5} 'infers Double()
Dim c = {"1", "2", "3"} 'infers String()
Becareful not to mix in types the compiler can not infer:
' WARNING: Make sure you used types that can be inferred.
' The next example will generation a warning if OPTION STRICT ON
' or infer a type of Object if OPTION STRICT OFF
Dim d = {1, "123"} 'infers Object() (warning with Option Strict On)
Create multidimensional arrays with array literals:
' Create multidimensional arrays by nesting array array literals:
'Nested array literals can be used to produce multidimensional arrays:
Dim f = {{1, 2, 3}, {4, 5, 6}} 'infers Integer(,)
Dim g = {({1, 2, 3}), ({4, 5, 6})} 'infers Integer()() (jagged array)
...
|