我需要帮助将这个for循环转换为VB.NET中的LINQ / Lambda表达式:
For Each dr As DataRow In dt.Rows
Dim firstName As String = CStr(dr("FirstName")).ToLower()
Dim lastName As String = CStr(dr("LastName")).ToLower()
If Not String.IsNullOrEmpty(firstName) AndAlso Not String.IsNullOrEmpty(lastName) Then
If firstName.ToLower = "john" AndAlso lastName.ToLower = "doe" Then
Return "Found"
End If
End If
Next
Return "Not Found"
谢谢!
答案 0 :(得分:3)
试试这个:
Dim row = dt.AsEnumerable().Where(Function(f) f.Field(Of String)("FirstName").ToLower = "john" AndAlso f.Field(Of String)("LastName").ToLower = "doe").FirstOrDefault()
Return If(row Is Nothing, "Not Found", "Found")