在.NET2中使用VB
Public Class GroupSID
Private _groupName As String
Private _sid As String
Public Property GroupName() As String
Get
Return _groupName
End Get
Set(ByVal value As String)
_groupName = value
End Set
End Property
Public Property SID() As String
Get
Return _sid
End Get
Set(ByVal value As String)
_sid = value
End Set
End Property
End Class
填充列表后,我想找到具有匹配groupName的项目(只有1个)
类似(伪VB / C#)
'Dim result As GroupSID = ListOfGroupSID.Find(x => x.GroupName == groupName)
来自:http://www.codeproject.com/Articles/388257/Csharp-Tips-Using-delegate-in-List-Find-predicate
' expression expected error on Function(p)
Dim result As GroupSID = ListOfGroupSID.Find(Function(p) p.GroupName = groupName)
问题是VB8 / .NET2不允许这样做..
答案 0 :(得分:2)
匿名函数(lambda)在VB8 / .Net2中不可用,因此您必须将谓词定义为单独的方法:
Function BelongsToSameGroup(ByVal group As GroupSID) As Boolean
Return group.GroupName = groupName ' need to be accessible
End Function
' usage
Dim result As GroupSID = ListOfGroupSID.Find(AddressOf BelongsToSameGroup)