static void Main(string[] args) { List <Action> actions = new List <Action>(); DisplayClass1 displayClass1 = new DisplayClass1(); for (displayClass1.i = 0; displayClass1.i < 10; ++displayClass1.i) { actions.Add(new Action(displayClass1.Lambda)); } foreach (Action a in actions) { a(); } }
internal static void CompiledCachedTranslation() { using (AdventureWorks adventureWorks = new AdventureWorks()) { int minLength = 1; DisplayClass1 displayClass1 = new DisplayClass1() { minLength = minLength }; IQueryable <ProductCategory> queryWithClosure1 = adventureWorks.ProductCategories .Where(category => category.Name.Length >= displayClass1.minLength); queryWithClosure1.Load(); minLength = 10; DisplayClass1 displayClass2 = new DisplayClass1() { minLength = minLength }; IQueryable <ProductCategory> queryWithClosure2 = adventureWorks.ProductCategories .Where(category => category.Name.Length >= displayClass2.minLength); queryWithClosure2.Load(); } }