Last active
August 29, 2015 14:05
-
-
Save mclasson/2b3a49f98d8c3a56e118 to your computer and use it in GitHub Desktop.
Linq deferred execution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
//Filter out a small subset of the data [zip code, annual income] | |
var listSmall = list.Where(i => i > 100000 && i < 150000); | |
//Now use the small subset and loop through it | |
//E.g. examine the first 1000 rows | |
var result = new List<int>(); | |
for (int i = 0; i < 1000; i++) | |
{ | |
int _i = listSmall.Where(o => o == 100100 + i).Single(); | |
result.Add(_i); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment