Maciej Los
Пожалуйста, взгляните на пример:
Dim MainList As List(Of List(Of String)) = New List(Of List(Of String)) From _
{ _
New List(Of String) From {"a","b","c"}, _
New List(Of String) From {"d","a","f", "c", "h"}, _
New List(Of String) From {"i","c"}, _
New List(Of String) From {"k","d","h"}, _
New List(Of String) From {"e","o","p"}, _
New List(Of String) From {"q","f","s", "g", "u"}, _
New List(Of String) From {"v","z","g","z"} _
}
Dim SearchValue As String = "a"
'#1
'returns sublists containing serached value
Dim subListContainingSerachedValue = _
MainList _
.Where(Function(x) x.Contains(SearchValue)) _
.ToList()
'#2
'returns AnonymousType(Of String, String, Boolean)
Dim OnlySearchedValues = _
MainList _
.SelectMany(Function(x) _
x.Select(Function(y) New With _
{
.OrigValue = y, _
.SearchedValue = SearchValue, _
.IsOnTheList = y.Any(Function(z) z=SearchValue) _
}) _
) _
.ToList()
Результаты:
'#1
List<String> {"a", "b", "c"}
List<String> {"d", "a", "f", "c", "h"}
'#2
OrigValue SearchedValue IsOnTheList
a a True
b a False
c a False
d a False
a a True
f a False
c a False
h a False
i a False
c a False
k a False
d a False
h a False
e a False
o a False
p a False
q a False
f a False
s a False
g a False
u a False
v a False
z a False
g a False
z a False