fork download
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Test
  6. {
  7.  
  8. static int counter = 0;
  9.  
  10. public static IEnumerable<T> CountedEnum<T>(IEnumerable<T> ee) {
  11. foreach (var e in ee) {
  12. counter++;
  13. yield return e;
  14. }
  15. }
  16.  
  17. public static void Main() {
  18. var Numbers= CountedEnum(new int[5]{5,2,3,4,5});
  19. var query = from a in Numbers
  20. where a== Numbers.Max (n => n)
  21. select a;
  22.  
  23. foreach (var element in query)
  24. Console.WriteLine (element);
  25.  
  26. Console.WriteLine("Count: {0}", counter);
  27. }
  28. }
Success #stdin #stdout 0.03s 38048KB
stdin
Standard input is empty
stdout
5
5
Count: 30