Grasshopper

algorithmic modeling for Rhino

Does the following declaration illustrates the difference between
'{}' vs '()'?

Dim names()() As String = {New String() {"Faraz", "Gates"}, _
New String() {"Hejlsberg", "Gosling"}}

Views: 6195

Replies to This Discussion

AFAIK VB.NET does not use square brackets [] at all. Curly brackets are used when creating an array manually as you've done.

FWIW, the following page might help if you've got some question regarding syntax differences between VB.NET and C#...

http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
Sorry, Damien. I intend to ask the difference between () with {}.

AFAIK=As Far As I Know?
FWIW=For What It's Worth?

I have corrected my post.

Thanks for the help!
Yes those acronymns are correct.

Regular brackets () are for several things in VB. First is for function/sub arguments, so
Sub MySubroutine (SomeArgument as Object)

Secondly its for declaring objects as any array, so
Dim myStringArr () as String

Curly brackets {} are used for actually specifying the content of an array. So if you wanted to actually specify what was in an array, then you could do something like the following
Dim myStringArr() as String = {"This", "array", "contains", "strings"}
However, you can NOT separate that line into two separate statements like follows
Dim myStringArr() as String
myStringArr = {"This", "array", "contains", "strings"} 'This is illegal

So curly brackets are only really used right when you're creating an array and cannot be used after declaration.

The only other place you'll see curly brackets are in string format functions and they're kind of implied...
RhUtil.RhinoApp.Write("{0}, how are {1}?", "Hello", "you")
'''Results in "Hello, how are you?"
Damien:

The above explanation is very clear! Thx.

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service