Skip to content

Instantly share code, notes, and snippets.

@mclasson
Created August 18, 2014 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mclasson/3e7b39f3282d0e38d082 to your computer and use it in GitHub Desktop.
Save mclasson/3e7b39f3282d0e38d082 to your computer and use it in GitHub Desktop.
//Prepare test data. Could be a set returned
//from a database query
var list = new List<int>();
for (int i = 0; i < 1000000; i++)
{
list.Add(i);
}
//Prepare a list to hold the results
//E.g list of all users born a certain year
var listOfInts = new List<IEnumerable<int>>();
for (int i = 0; i < 10; i++)
{
//Select from the large list all users
//that satisfy the criteria
listOfInts.Add(list.Where(a => a == i));
}
//Now, loop through all years and select the
//first user for every year
foreach(var l in listOfInts)
{
Console.WriteLine(l.First());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment