I have a an array of strings:e.g:
string [] names ={"P","A","B","G","F","K","R"}
I have another array :
string [] subnames={"P","G","O"}
How can we check whether names array has any elements of subnames array.
In the above example "P" and "G" are there in names.
The absolute simplest way would be to use the Enumerable.Intersect method. Then us the Any method on the result
bool containsValues = names.Intersect(subnames).Any();
This will work too:
bool result = names.Any(subnames.Contains);
EDIT
This code may look incomplete but it actually works (method group approach).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With