in

vbCity Blogs

New (temp) place for vbCity Blogs

Mike McIntyre's .NET Journal

Visual Basic 2010 - Array Literals

 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)

 

Mike McIntyre's .Net Journal

getdotnetcode.com

About Mike McIntyre

I  am a programmer, developer, and system architect with 29+years experience including state-of-the-art application development frameworks and languages including Visual Studio versions 2002-2010, .NET Framework versions 1-4, C#, and Visual Basic.

I am a mentor, trainer, and coach in the Microsoft .NET technical community. DevCity is my favorite community site. You can find examples of my involvement with DevCity in the site articles, newsletter articles, and my posts in the forum.

Since 2002 I have hosted a .NET site at http://www.getdotnetcode.com, a place with free and inexpensive Visual Basic and C# source code that can be purchased on an 'as needed' basis.

In 2007 I established a .NET search engine, 'Resources for .NET Developers' at http://dot-net-resources-swicki.eurekster.com

Copyright 1998-2009 vbCity.com LLC
Powered by Community Server (Non-Commercial Edition), by Telligent Systems