Reputation: 57
please help in creating simple c# Linq query
List<A> X;
class A{
public string phone;
...some other props
}
class B{
public string xyz;
public List<B> bobj;
}
class C{
public string pqr;
public B;
}
..
Now I have list of C;
List<C> tobesearched;
How to get all C i.e. List<C>
from tobesearched
for a phone which contains "123"
Upvotes: 2
Views: 606
Reputation: 925
If I understood your question correctly, you're looking to filter your List<C>
where any B has a bobj
which has a phone
containing 123, right?
IEnumerable<C> result = tobesearched.Where(t => t.b.bobj.Any(u => u.phone.Contains("123")));
..or with the class you posted in the comment below:
IEnumerable<Cdaily_snapshot> result =
tobesearched.Where(t => t.customer.phonenumbers.Any(u => u.phone.Contains("123")));
Upvotes: 1