fork download
  1. using System;
  2. using System.Linq;
  3. using System.Linq.Expressions;
  4. using System.Collections.Generic;
  5.  
  6. namespace ConsoleApp1
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. int[] arr = { 1, 2, 3, 4, 5, 6, 7, 8 };
  13. var param = Expression.Parameter(typeof(int), "x");
  14. var modexp = Expression.Modulo(param, Expression.Constant(2));
  15. var body = Expression.Equal(modexp, Expression.Constant(0));
  16. Expression<Func<int, bool>> cond = Expression.Lambda<Func<int, bool>>(body, param);
  17. var query = arr.Where(cond.Compile());
  18. foreach (int x in query) Console.Write(x + "\t");
  19. }
  20. }
  21. }
  22.  
Success #stdin #stdout 0.05s 20092KB
stdin
Standard input is empty
stdout
2	4	6	8