Given 2 int arrays e.g, foo and bar, what’s the most efficient way to check that the array bar contains at least one item that foo contains. should return true/false.
I’m suspecting nested foreach but just wondering if there’s a nicer way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using LINQ:
Note: Using
Any()assures that the intersection algorithm stops when the first equal object is found.