Newbie Syntax Help

  • Thread starter Thread starter hharry
  • Start date Start date
H

hharry

Hi All,

I need some help with a piece a code in an app I am modifying. I have
come across this line..

Dim mytring(,) As String = {{"sSomeStr", 10}, {"sAnother", 12}}

Can someone explain it too me ?


Thanks in advance
 
This part declares a two dimension String array:

Dim mytring(,) As String

This part is an array initializer with two array initializers nested within
it.

{{"sSomeStr", 10}, {"sAnother", 12}}

An array intializer is one way to initialize and array.

IF OTION STRICT OFF - The result of the full statement will be an array like
this:

mytring(0,0) contains "sSomeStr"
mytring(0,1) contains "10"
mytring(1,0) contains "sAnother"
mytring(1,1) contains "12"

The outer array intializer (between the outer brackets {}) contains data for
two dimentions by nesting within it two array intializers separated by a
comma:

{"sSomeStr", 10}
and
{"sAnother", 12}

each of the two inner initializers provides data to fill two elements within
the dimention it occupies.

FYI - IF OTION STRICT ON - The code will not compile.


--
Mike

Mike McIntyre
Visual Basic MVP
www.getdotnetcode.com
 
hharry said:
I need some help with a piece a code in an app I am modifying. I have
come across this line..

Dim mytring(,) As String = {{"sSomeStr", 10}, {"sAnother", 12}}

This code will declare a variable of type "two-dimensional array of string"
which is later filled with a 2 × 2 array of strings.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top