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