LINQ List A (list of strings) "partial" has any member of list B (list of strings)
For instance:
List A has "Car","Bicycle"
List B has "Blue Car", "Red Baloon","Random stuff"
I want it to return true since List B has "Car" in it
10 Replies
Combine
.Any()
with .Contains()
.Any()
on the list, .Contains()
on the string as a predicateif (a.Any(item1=> b.Any(item2=> item1.Contains(item2))))
Like this?
Does it work?
doesnt look like it does
Narrator: it didn't work
You need to use Contains on the strings themselves
In the second list
item1.Contains item1 is already a string
isnt it?
Yes, but unless I misunderstood it sounds like you have the lookup inverted. You're asking if "Car" contains "Blue Car" I think
"Car" does not contain "Blue Car"
"Blue Car" contains "Car"
Ero#1111
REPL Result: Success
Result: bool
Compile: 593.183ms | Execution: 71.943ms | React with ❌ to remove this embed.
so basically what you already had, just invert the lists
Thanks!