使用VB,在单词之后放置“()”是什么?

时间:2009-05-13 14:17:15

标签: vb.net

在单词之后放“()”是什么意思?有时它不起作用

5 个答案:

答案 0 :(得分:10)

<强>方法

如果你看一下Console.WriteLine,这个方法的常用形式就是一个或多个争论,例如。

Console.WriteLine("Hello World")

但是,一个重载不带参数,只打印一个空行

Console.WriteLine()

空大括号显示没有争论的方法调用。

<强>阵列

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

以下两个声明变量,稍后将分配一个字符串数组。

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

答案 1 :(得分:2)

它调用一种方法。它也用于声明一个数组,具体取决于上下文。

答案 2 :(得分:1)

用于函数或方法调用的paranthesis。例如,如果你有一个名为Run的方法,你可以通过说MyDog.Run()

来调用它

属性和常规变量不同,不使用paranthesis。例如,MyDog.FurColor = Blue

某些功能需要参数。以我们的示例为例,参数可能是运行的距离。所以,MyDog.Run(10)

但是,鉴于你的其他问题,你可能已经知道了这个问题的答案......

答案 3 :(得分:0)

我们使用()用1)方法或2)函数或3)子程序或4)程序等单词。

阵列也使用它。

Method =可以由对象执行的操作。在Visual Basic .NET中,方法定义为子和函数。

答案 4 :(得分:0)

扩展Mehrdad所说的话:

以下行使用“()”来声明数组:

'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"}

以下行不声明数组:

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