Advertisement
Guest User

Closure Weirdness

a guest
Feb 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.44 KB | None | 0 0
  1. namespace CSharpTests
  2. {
  3.     class Program
  4.     {
  5.         private static event Action myEvent = delegate { };
  6.  
  7.         static void Main(string[] args)
  8.         {
  9.             for(int i = 0; i < 100; i++)
  10.             {
  11.                 var jj = i.ToString();
  12.                 myEvent += () => { Console.WriteLine(string.Format("Line {0}: {1}",jj,i)); };
  13.             }
  14.  
  15.             myEvent();
  16.  
  17.             Console.Read();
  18.         }
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement