fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8. public class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. var x = new List<Action>();
  13. var y = new List<string>{"1", "2", "3"};
  14. for(int i =0; i< y.Count(); i++)
  15. {
  16. Action z = ()=>{Console.WriteLine(y[i]);};
  17. x.Add(z);
  18. }
  19. //Your code goes here
  20. x[0]();
  21. }
  22. }
  23. }
Runtime error #stdin #stdout #stderr 0.02s 14488KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Unhandled Exception:
System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00011] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Rextester.Program+<Main>c__AnonStorey1.<>m__0 () [0x00000] in <2e9f241316e1412eadf16c54c80516a7>:0 
  at Rextester.Program.Main (System.String[] args) [0x00094] in <2e9f241316e1412eadf16c54c80516a7>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) [0x00011] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.ThrowHelper.ThrowArgumentOutOfRangeException () [0x00000] in <8f2c484307284b51944a1a13a14c0266>:0 
  at System.Collections.Generic.List`1[T].get_Item (System.Int32 index) [0x0000c] in <8f2c484307284b51944a1a13a14c0266>:0 
  at Rextester.Program+<Main>c__AnonStorey1.<>m__0 () [0x00000] in <2e9f241316e1412eadf16c54c80516a7>:0 
  at Rextester.Program.Main (System.String[] args) [0x00094] in <2e9f241316e1412eadf16c54c80516a7>:0