Alex Rivera | Logout

How can we check whether one array contains one or more elements of another array in #?

Asked 2012-06-21T13:36:19.770
15

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.

Edit
Report

1 Answer

0

Linq is the simplest I think:

from n1 in names
join n2 in subnames on n1 equals n2
select n1;
answered 2012-06-21T13:41:18.893

Your Answer