Sample Queries application使用 !运算符引用 DataRow 中的字段。
Option Strict Off
Imports System.Data
Imports System.Linq
Module Program
Public Sub Main()
Dim numbers() As Integer = {5, 4, 1, 3, 9, 8, 6, 7, 2, 0}
Dim table As New DataTable("Numbers")
table.Columns.Add("number", GetType(Integer))
For Each n In numbers
table.Rows.Add(New Object() {n})
Next
Dim lowNums = From row In table.Rows _
Where row!number < 5
Select row
For Each x In lowNums
Console.WriteLine(x!number)
Next
End Sub
End Module
什么是!接线员打电话? 规则记录在哪里?
最佳答案
这是(在这种情况下)Exclamation point Operator :
“仅在类或接口(interface)上使用 ! 运算符作为字典访问运算符。类或接口(interface)必须具有接受单个字符串参数的默认属性。紧跟在 ! 运算符后面的标识符将成为参数值作为字符串传递给默认属性。”
所以代码row!number
相当于row("number")
该运算符是 VB6 遗留下来的,在 VB.NET IMO 中应避免使用。它与 LINQ 并没有具体的关系。
您的示例有点人为,因为它无法编译(即使使用 Option Strict Off) - 编辑:现在已对此进行了修改,但仍然无法使用 Option Strict Off 进行编译
注意“! 字符也用作 Single 类型字符。” 例如暗淡! = 0.12
但这不是您上下文中代码的意图
关于.net - 我在哪里可以获得有关 ! VB.Net 在 Linq to DataSet 中使用的运算符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26428491/