【问题标题】:Square brackets around function name函数名两边的方括号
【发布时间】:2014-07-04 19:30:47
【问题描述】:

我目前试图理解代表,并偶然发现了以下 sn-p:

Function [Select](ByVal numbers As List(Of Integer), ByVal filter As Filter) As List(Of Integer)
    Dim result As New List(Of Integer)
    For Each number In numbers
        ' call delegate
        If filter(number) = True Then
            result.Add(number)
        End If
    Next
    Return result
End Function

我搜索了一个解释,但我能找到的只是this,但这并不能帮助我理解我找到的 sn-p。谁能帮我理解方括号[Select] 的用途?

【问题讨论】:

  • 这是您在 VB 中转义特殊名称的方式。 SELECT 是关键字(如Select Case),因此要将其用作属性或函数名称,您可以使用括号对其进行转义。您可以执行相同的操作来指定您正在使用的名称,该名称也是 NET 类型名称,例如 ImageVersion

标签: .net vb.net syntax square-bracket


【解决方案1】:

它们存在是因为 Select 关键字已用于 Select... Case 语句。因此,括号用于通知编译器和 IDE 您不想使用关键字,您只希望它作为“普通”文本(无论在给定上下文中可能是什么)。

仅供参考,您也必须在 SQL-Server 中做同样的事情。

【讨论】:

  • 啊好的,我明白了!谢谢!
猜你喜欢
  • 2018-01-25
  • 2011-10-01
  • 2017-01-21
  • 1970-01-01
  • 2019-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-16
相关资源
最近更新 更多