这是什么{!在特定的代码行中是什么意思? [英] What does this { ! } mean in the specific line of code?

查看:25
本文介绍了这是什么{!在特定的代码行中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读一段代码,该代码块读取 Microsoft Access 数据库架构.

I was reading a block of code, which reads an Microsoft access database schema.

在其他人之间我看到那行代码在循环中

Between others i saw that line of code in a loop

ColName = SchemaTable.Rows(i)!COLUMN_NAME.ToString 

为什么感叹号用于 { !}?

Why the exclamation mark is used for { ! }?

推荐答案

来自 MSDN: 代码中的特殊字符 (Visual Basic)

感叹号 (!) 运算符

使用!操作符仅在类或接口上作为字典访问操作员.类或接口必须有一个默认属性接受单个字符串参数.紧随其后的标识符这 !运算符成为传递给默认值的参数值属性作为字符串.

Use the ! operator only on a class or interface as a dictionary access operator. The class or interface must have a default property that accepts a single String argument. The identifier immediately following the ! operator becomes the argument value passed to the default property as a string.

Public Class hasDefault
  Default Public ReadOnly Property index(ByVal s As String) As Integer
    Get
      Return 32768 + AscW(s)
    End Get
  End Property
End Class
Public Class testHasDefault
  Public Sub compareAccess()
    Dim hD As hasDefault = New hasDefault()
    MsgBox("Traditional access returns " & hD.index("X") & vbCrLf & 
      "Default property access returns " & hD("X") & vbCrLf & 
      "Dictionary access returns " & hD!X)
  End Sub
End Class

MsgBox 的三行输出都显示值 32856.第一行使用传统的访问属性索引,第二行利用索引是类的默认属性的事实hasDefault,第三个使用字典访问类.

The three output lines of MsgBox all display the value 32856. The first line uses the traditional access to property index, the second makes use of the fact that index is the default property of class hasDefault, and the third uses dictionary access to the class.

注意 ! 的第二个操作数运算符必须是有效的 Visual未用双引号 (" ") 括起来的基本标识符.在换句话说,您不能使用字符串文字或字符串变量.这对 MsgBox 调用的最后一行进行更改后会生成一个错误,因为X"是一个封闭的字符串文字.

Note that the second operand of the ! operator must be a valid Visual Basic identifier not enclosed in double quotation marks (" "). In other words, you cannot use a string literal or string variable. The following change to the last line of the MsgBox call generates an error because "X" is an enclosed string literal.

"Dictionary access returns " & hD!"X") 

对默认集合的引用必须是明确的.特别是你不能使用!后期绑定变量上的运算符.

References to default collections must be explicit. In particular, you cannot use the ! operator on a late-bound variable.

这篇关于这是什么{!在特定的代码行中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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