fork download
  1. using System;
  2. using System.Linq;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var list = new byte[] { 0, 0, 2, 0, 1 };
  9. int LinqCnt = 0;
  10. var tmp = list.Where(x =>
  11. {
  12. LinqCnt++;
  13. Console.WriteLine("In where: " + LinqCnt + ", x = " + x);
  14. return x > 0;
  15. });
  16.  
  17. Console.WriteLine("After where: " + LinqCnt);
  18.  
  19. if (tmp.First() == tmp.Last())
  20. Console.WriteLine(LinqCnt + " ");
  21.  
  22. Console.WriteLine("After enumeration: " + LinqCnt);
  23. }
  24. }
Success #stdin #stdout 0.05s 24048KB
stdin
Standard input is empty
stdout
After where: 0
In where: 1, x = 0
In where: 2, x = 0
In where: 3, x = 2
In where: 4, x = 0
In where: 5, x = 0
In where: 6, x = 2
In where: 7, x = 0
In where: 8, x = 1
After enumeration: 8