brackets, braces and arrays

B

bric

Every time that I sit down to use an array I wonder a bit about
syntax. Even if it's a simple thing and I can just do it quickly and
get it out of the way.

The reason I wonder is this. (Most often I'm coding vb)

dim sTest(3) as string

is fine for grabbing my 4 test items.
But I've also gotten into the habit of doing this:

dim arParm as sqlparameter() = new sqlparameter(3){}

So are they both 2 ways of doing the same thing? Intellisense doesn't
give errors when I type a string array in this same manner as used
with the sqlparm.


And I recently noticed that in C# you do this:

string[] sTest = new string[3];

.... is this the corrolary for the vb syntax used above in my arParm
example?


And why the curly brackets at the end of the line? Are they ever used
for anything?

I figured I better ask this before too many years pass and I retire
without learning the basics.
:)

thanks
Brian
 
J

John Saunders

bric said:
Every time that I sit down to use an array I wonder a bit about
syntax. Even if it's a simple thing and I can just do it quickly and
get it out of the way.

The reason I wonder is this. (Most often I'm coding vb)

dim sTest(3) as string

is fine for grabbing my 4 test items.
But I've also gotten into the habit of doing this:

dim arParm as sqlparameter() = new sqlparameter(3){}

So are they both 2 ways of doing the same thing? Intellisense doesn't
give errors when I type a string array in this same manner as used
with the sqlparm.


And I recently noticed that in C# you do this:

string[] sTest = new string[3];

... is this the corrolary for the vb syntax used above in my arParm
example?


And why the curly brackets at the end of the line? Are they ever used
for anything?

The brackets at the end of the line can be used to initialize the array:

Dim arInt as Integer() = new Integer(3){0,1,2}
 

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

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top