tags:

views:

130

answers:

5

what does putting "()" after a word do? sometimes it doesn't work

+2  A: 

It calls a method. It's also used to declare an array, depending on the context.

Mehrdad Afshari
A: 

We use () with words which are 1) methods or 2) functions or 3) Sub-routines or 4) procedures etc.

Also arrays use it.

Method = An action that can be performed by an object. In Visual Basic .NET, methods are defined as Subs and Functions.

NinethSense
+1  A: 

The paranthesis are there for function or method calls. For example, if you have a method named Run you would call it by saying MyDog.Run()

Properties and regular variables are different and do not use paranthesis. For example, MyDog.FurColor = Blue

Some functions take parameters. Taking our example, a parameter might be how far to run. So, MyDog.Run(10)

But, given your other questions you probably already know the answer to this one...

Chris Lively
+9  A: 

Methods

If you look at Console.WriteLine, the commonly used forms of this method take one or more arguements e.g.

Console.WriteLine("Hello World")

However, one overload takes no parameters, and simply prints a blank line

Console.WriteLine()

Empty Braces show a method call with no arguements.

Arrays

Dim s as String ' declares one string
Dim as(10) as string ' declares 11 strings, accessed by position

The following both declare variables that will later be assigned an array of strings.

Dim n() as string
Dim m as string()
Binary Worrier
Assuming vb.net
Binary Worrier
A: 

To expand on what Mehrdad said:

The following lines use "()" to declare arrays:

'dynamic array w/o pre-set length'
Dim Doubles() As Double

'array of length 11'
Dim Doubles(10) As Double

'array of Strings initialized with three items'
Dim Strings() As New String() {"String1", "String2", "String3"}

The following line does NOT declare an array:

'here the "()" are treated as a call to the MyObject constructor'
Dim MyObjects As New MyObject()
Dan Tao