程序代码: |
Sub IEnumerableWhere1()
Dim fruits As New List(Of String)(New String() _
{"apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry"})
'将结果限制为以下字符串
'长度小于 6。
Dim query As IEnumerable(Of String) =
fruits.Where(Function(fruit) fruit.Length < 6)
'显示结果
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
MsgBox(output.ToString())
End Sub
Sub IEnumerableWhere2()
Dim fruits As New List(Of String)(New String() _
{"apple", "passionfruit", "banana", "mango",
"orange", "blueberry", "grape", "strawberry"})
'将结果限制为以下字符串
'长度小于 6。
Dim query As IEnumerable(Of String) =
fruits.Where(AddressOf w)
'显示结果
Dim output As New System.Text.StringBuilder
For Each fruit As String In query
output.AppendLine(fruit)
Next
MsgBox(output.ToString())
End Sub
Function w(ByVal F As String) As Boolean
If F.Length < 6 Then
Return True
Else
Return False
End If
End Function
Sub IEnumerableWhere3()
' Create an array of integers.
Dim numbers() As Integer = {0, 30, 20, 15, 90, 85, 40, 75}
' 将结果限制为以下数字
' 值小于或等于其索引乘以 10。
Dim query As IEnumerable(Of Integer) =
numbers.Where(Function(number, index) number <= index * 10)
'显示结果
Dim output As New System.Text.StringBuilder
For Each number As Integer In query
output.AppendLine(number)
Next
MsgBox(output.ToString())
End Sub
Sub IEnumerableWhere4()
' Create an array of integers.
Dim numbers() As Integer = {0, 30, 20, 15, 90, 85, 40, 75}
' 将结果限制为以下数字
' 值小于或等于其索引乘以 10。
Dim query As IEnumerable(Of Integer) =
numbers.Where(AddressOf w1)
'显示结果
Dim output As New System.Text.StringBuilder
For Each number As Integer In query
output.AppendLine(number)
Next
MsgBox(output.ToString())
End Sub
Function w1(ByVal F As Integer, ByVal i As Integer) As Boolean
'MsgBox(F & " " & i)
If F < i * 10 Then
Return True
Else
Return False
End If
End Function
IEnumerableWhere1 和 IEnumerableWhere2 效果是一样的
IEnumerableWhere3 和 IEnumerableWhere4 效果是一样的
[本日志由 tiancao1001 于 2022-02-10 05:26 PM 编辑]
|
暂时没有评论
发表评论 - 不要忘了输入验证码哦! |