I am using LINQ - VB.Net
I want to filter my List object by passing String object in the where.
Dim _permittedTransactionCodes As List(Of String) = Nothing 'String object
it is populated with data.
Dim tap100transCodeInfos As List(开发者_如何学COf Tap100transCodeInfo) = _dal.GetActiveTap100transCodeByHdrScreenCde(UCase(screenId), "TRAN_CDE")
i am trying something below, but not getting the filtered results
tap100transCodeInfos.Where(Function(x) _permittedTransactionCodes.Contains(x.TranCde))
any idea?
Thanks
Make sure to assign the output of the Where
function to a variable. Where
does not filter the existing list, but returns a new filtered list.
Dim result As IEnumerable(Of Tap100transCodeInfo) = _
tap100transCodeInfos.Where(Function(x) _
_permittedTransactionCodes.Contains(x.TranCde) _
)
Then result
should have the filtered results.
EDIT:
Where
returns an IEnumerable(Of T)
so if you are assigning the output to the same variable you need to append .ToList()
to the end of the statement (or define tap100transCodeInfos
to be an IEnumerable(Of Tap100transCodeInfo)
from the start).
tap100transCodeInfos = _
tap100transCodeInfos.Where(Function(x) _
_permittedTransactionCodes.Contains(x.TranCde) _
).ToList()
精彩评论