With VB, what does "()" do after a word?

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

0


a source to share


5 answers


To find out 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 next line does NOT declare an array:

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

      

0


a source


Methods

If you look at Console.WriteLine the commonly used forms of this method take one or more arguments, eg.

Console.WriteLine("Hello World")

      

However, one overload takes no parameters and just prints an empty string

Console.WriteLine()

      



Empty braces indicate a method call with no arguments.

Arrays

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

      

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

Dim n() as string
Dim m as string() 

      

+10


a source


It calls the method. It is also used to declare an array based on context.

+2


a source


Parathesis exists for function or method calls. For example, if you have a method named Run, you would name it by specifying MyDog.Run ()

Properties and regular variables are different and don't use paranthesis. For example, MyDog.FurColor = Blue

Some functions take parameters. In our example, the parameter could be how far to work. So MyDog.Run (10)

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

+1


a source


We use () with words: 1) methods or 2) functions or 3) subroutines or 4) procedures, etc.

Arrays are also used.

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

0


a source







All Articles