tags:

views:

67

answers:

2

Here's the scenario:

Given a List of Outputs each associated with an integer based GroupNumber. For each distinct GroupNumber within the List of Outputs starting with the lowest GroupNumber (1). Cycle through that distinct group number set and execute a validation method.

Basically, starting from the lowest to highest group number, validate a set of outputs first before validating a higher groupnumber set.

Thanks, Matt

+1  A: 

If you need them as groups:

var qry = source.GroupBy(x=>x.GroupNumber).OrderBy(grp => grp.Key);
foreach(var grp in qry) {
    Console.WriteLine(grp.Key);
    foreach(var item in grp) {...}
}

If you just need them ordered as though they are grouped:

var qry = source.OrderBy(x=>x.GroupNumber);
Marc Gravell
+2  A: 

There's almost too many ways to solve this:

Here's one for a void Validate method.

source
  .GroupBy(x => x.GroupNumber)
  .OrderBy(g => g.Key)
  .ToList()
  .ForEach(g => Validate(g));


Here's one for a bool Validate method.

var results = source
  .GroupBy(x => x.GroupNumber)
  .OrderBy(g => g.Key)
  .Select(g => new
  {
      GroupNumber = g.Key,
      Result = Validate(g),
      Items = g.ToList()
  })
  .ToList();
David B