Hi can you guys help me with this, I have try several things. I need to search between two IEnumerables, here is the code.
IEnumerable<Project> Projects = new[] { new Project {id = "1", lan = "test1"}, new Project {id = "2", lan = "test1"}}
IEnumerable<string> lan = new [] { "test1", "test2"};
IEnumerable<string> indexFiltered = ?;
I need to do a linq query that return the Project.id thats have any Project.lan in lan.
Any idea?
I'd use a HashSet rather than an array, as it allows check-if-contains as an O(1), rather than O(n), operation:
HashSet<string> lan = new HashSet<string> { "test1", "test2" };
IEnumerable<string> indexFiltered = projects
.Where(p => lan.Contains(p.lan))
.Select(p => p.id);
var results = projects.Where(p => lan.Contains(p.lan));
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