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

how to search a List<list<int>> with another List<int> in c#

I have the following lists of list.

List<List<int>> paths = new List<List<int>>();
paths.Add(new List<int>() { 0,1 });
paths.Add(new List<int>() { 0, 2 });
paths.Add(new List<int>() { 0, 4 });
paths.Add(new List<int>() { 1, 2 });
paths.Add(new List<int>() { 0, 3 });

and I have another List of int like this

List<int> ends = new List<int>(){3,4};

Now I need to filter records where any number in the inner list in paths contains any numbers from the ends list, which for this example would be the following records.

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

{0,3}
{0,4} 

I tried something like this

paths.Where(x => x.Where(y => ends.Contains(y))).ToList();

>Solution :

 paths.Where(x => x.Any(z => ends.Contains(z)))
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