fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace ConsoleApp1
  5. {
  6. static class MyLinq
  7. {
  8. public static IEnumerable<int> Where(this int[] arr, Func<int, bool> cond)
  9. {
  10. int[] result = new int[arr.Length];
  11. int j = 0;
  12. for (int i = 0; i < arr.Length; i++)
  13. if (cond(arr[i]))
  14. result[j++] = arr[i];
  15. Array.Resize(ref result, j);
  16. return result;
  17. }
  18. }
  19.  
  20. class Program
  21. {
  22. static bool myfunc(int x)
  23. {
  24. return x < 5;
  25. }
  26. static void Main(string[] args)
  27. {
  28. int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
  29. var query = arr.Where(myfunc);
  30. foreach (int x in query) Console.Write(x + "\t");
  31. }
  32. }
  33. }
  34.  
Success #stdin #stdout 0.03s 14992KB
stdin
Standard input is empty
stdout
1	2	3	4