Problem with LINQ, anonymous types, and closures
问题 I have a piece of code that filters a list using LINQ, creates a list of instances of an anonymous type, and assigns an event handler to each instance: // Select every linear expression and create a menu item from it var items = from expr in expressionList.Expressions where expr.Type == ExpressionType.Linear let stdExpr = (StandardExpression)expr select new { Menu = new ToolStripMenuItem(stdExpr.Expression), // string stdExpr.Slot // int }; // Wire a Click event handler to each menu to set