karl.r
karl.r

Reputation: 971

LINQ to a class in a group in a list

I have a

List<PublicGrouping<DateTime,Event>> 

used in a LongListSelector for a windows phone 7 project. PublicGrouping implements IGrouping.

How can I get a List of PublicGrouping where Event.X = Y?

Upvotes: 1

Views: 420

Answers (1)

SLaks
SLaks

Reputation: 887757

You're trying to find all groups Where Any of the Events in the group meet a condition:

var yGroups = list.Where(g => g.Any(e => e.X == y));

EDIT:
You're trying to Select new groups from the Events in the old Groups Where some condition, and you only want non-empty groups:

var yGroups = list.Select(g => new PublicGrouping(g.Key, g.Where(e => e.X == y))
                  .Where(g => g.Any());

Upvotes: 3

Related Questions