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

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

问题描述

我正在读一段代码,它读取一个Microsoft访问数据库模式。



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

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

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

解决方案

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


感叹号(!)运算符



使用!运算符只能在类或接口上作为字典访问
运算符。类或接口必须具有
接受单个String参数的默认属性。紧跟在
之后的标识符!运算符将作为字符串传递给默认
属性的参数值。

 公共类hasDefault 
默认Public ReadOnly属性索引(ByVal s As String)As Integer
获取
返回32768 + AscW(s)
结束获取
结束属性
结束类
public class testHasDefault
Public Sub compareAccess()
Dim hD As hasDefault = New hasDefault()
MsgBox(传统访问返回& hD.index(X)& vbCrLf& ;
默认属性访问返回& hD(X)& vbCrLf&
字典访问返回& hD!X)
End Sub
结束class

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

请注意,第二个操作数!操作符必须是一个有效的Visual
基本标识符不包含在双引号()中。在
的其他单词中,您不能使用字符串文字或字符串变量。更改为MsgBox调用最后一行的
会生成
错误,因为X是一个封闭的字符串文字。

 字典访问返回& hD!X)

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



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 { ! }?

解决方案

From MSDN: Special Characters in Code (Visual Basic)

Exclamation Point (!) Operator

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

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.

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天全站免登陆