Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

check if a item in list, exists in another list with linq

i’m new in c# ,sorry for bad question.

how can i say, if an item in a list,

exists in another list?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

l know it can be done using linq functions, but I don’t know which method can help.

I want something like this:


bool Exists(List<int> list1, List<int> list2)

{
    // if the value of the first index of list1 exists in list2, return true.

}

>Solution :

well

you can do this

bool Exists(List<int> list1, List<int> list2)
{
var firstIndex=list1.First();

return list2.Any(num=> num == firstIndex);
}

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading