Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- List<Func<int>> actions = new List<Func<int>>();
- int variable = 0;
- while (variable < 5)
- {
- actions.Add(() => variable * 2);
- ++ variable;
- }
- foreach (var act in actions)
- {
- Console.WriteLine(act.Invoke());
- }
- while (variable < 5)
- {
- int copy = variable;
- actions.Add(() => copy * 2);
- ++ variable;
- }
- for (int i=0; i < 10; i++) // Just one variable
- foreach (string x in foo) // And again, despite how it reads out loud
- List<Func<int>> actions = new List<Func<int>>();
- int variable = 0;
- while (variable < 5)
- {
- int variable1 = variable;
- actions.Add(() => variable1 * 2);
- ++variable;
- }
- foreach (var act in actions)
- {
- Console.WriteLine(act.Invoke());
- }
- Console.ReadLine();
- while( variable < 5 )
- {
- int copy = variable;
- actions.Add( () => copy * 2 );
- ++variable;
- }
- for (int counter = 1; counter <= 5; counter++)
- {
- new Thread (() => Console.Write (counter)).Start();
- }
- for (int counter = 1; counter <= 5; counter++)
- {
- int localVar= counter;
- new Thread (() => Console.Write (localVar)).Start();
- }
Add Comment
Please, Sign In to add comment