I'm trying to find the best approach to filtering a list with C# (3.5) but I can't seem to find any examples that are similar to my situation. I'm open to using lambdas or linq.
The thing that is unique compared to most of the examples that I've found, is that my list items each have child arrays for example...
var employees= new List<Employee>
{
new Employee{Name = "John",Nicknames="'J','Big J','Big John'"},
new Employee{Name = "Joshua",Nicknames="'J','Josh','Joshman'"},
}
I'd then like to filter that list something like this...
//using linq
var matchesByNickname =
from worker in employees
where worker.Nicknames.Equals("J")
select worker;
//or lambda
var employees2 = employees
.Where(e => Nicknames.Exists(n => n.Nickname == "J"))
But of course since Nicknames is itself an array I cannot use .Equals or .Contains etc. What would be the best approach to filtering a list of this type?
UPDATE: In trying to keep my example simple I've misled you a bit. The list items do have true object arrays on them, not strings. My real world example is a list of custom product objects. The product object has a Regions property on it which is a list of Region objects. A product can have none, 1, or more than 1 region. The region object has a name and an id. So what I really want is to filter a list of products, for any product assigned to a certain region.