VB.Net:方括号[参数]在过程声明中是什么意思? [英] VB.Net: what do square brackets [parameter] mean in a declaration of procedure?

查看:62
本文介绍了VB.Net:方括号[参数]在过程声明中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个 Sub delaration:

I have found this Sub delaration:

Private Sub ReceivedText(ByVal [text] As String) 'input from ReadExisting
        If Me.lblStatus.InvokeRequired Then
            Dim x As New SetTextCallback(AddressOf ReceivedText)
            Me.Invoke(x, New Object() {(text)})
        Else
            Me.lblStatus.Text &= [text] 'append text
        End If
    End Sub

我不明白 [text] 中的 [].这是什么意思 ?

I don't understand the [] in [text]. What does it mean ?

谢谢.

推荐答案

括号用于表示文本是变量或标识符,而不是类型或其他关键字.

The brackets are used to signify that the text is a variable or identifier and not a type or some other keyword.

例如,如果我愿意,我可以这样做:

For example, I can do something like this if I wanted to:

 Private Sub ReceivedText(ByVal [String] As String) 'input from ReadExisting
    If Me.lblStatus.InvokeRequired Then
        Dim x As New SetTextCallback(AddressOf ReceivedText)
        Me.Invoke(x, New Object() {([String])})
    Else
        Me.lblStatus.Text &= [String] 'append text
    End If
End Sub

如果没有括号,Visual Studio(例如)会认为 'String' 是一种类型并给出错误:关键字在标识符中无效".究竟如何命名标识符或变量是另一个问题.

Without the brackets Visual Studio (for example) will think that 'String' is a type and give you the error: "Keyword is not valid as in identifier". What to actually name identifiers or variables is a whole other question.

这篇关于VB.Net:方括号[参数]在过程声明中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆