最近了解了点LINQ,感觉蛮有意思的,用起来很舒服。
现在把动态条件心得拿出来和大家分享一下
Dim
l
As
New
List(
Of
Object
)
l.Add( New With {.ID = " 1 " , .Name = " Jim " , .Age = 21 })
l.Add( New With {.ID = " 2 " , .Name = " Sam " , .Age = 22 })
l.Add( New With {.ID = " 3 " , .Name = " Jack " , .Age = 23 })
Dim lc = From c In l _
Where getCondition(c) _
Select c
MsgBox (lc( 0 ).name)
Private Function getCondition( ByVal student As Object ) As Boolean
Dim value As Boolean = True
' 条件可以根据情况添加
value = value And student.ID = " 1 "
value = value And student.Age = 21
Return value
End Function
l.Add( New With {.ID = " 1 " , .Name = " Jim " , .Age = 21 })
l.Add( New With {.ID = " 2 " , .Name = " Sam " , .Age = 22 })
l.Add( New With {.ID = " 3 " , .Name = " Jack " , .Age = 23 })
Dim lc = From c In l _
Where getCondition(c) _
Select c
MsgBox (lc( 0 ).name)
Private Function getCondition( ByVal student As Object ) As Boolean
Dim value As Boolean = True
' 条件可以根据情况添加
value = value And student.ID = " 1 "
value = value And student.Age = 21
Return value
End Function
条件中可以设断点查看,感觉像是循环进行比较