fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. static Func<int, int, bool> ConstructRelation(string s)
  6. {
  7. switch (s)
  8. {
  9. case ">": return (Func<int, int, bool>)((a, b) => a > b);
  10. case "<": return (Func<int, int, bool>)((a, b) => a < b);
  11. case "==": return (Func<int, int, bool>)((a, b) => a == b);
  12. case ">=": return (Func<int, int, bool>)((a, b) => a >= b);
  13. case "<=": return (Func<int, int, bool>)((a, b) => a <= b);
  14. default: throw new ArgumentException("Unknown relation");
  15. }
  16. }
  17.  
  18. public static void Main()
  19. {
  20. Func<int, int, bool> rel = ConstructRelation(">");
  21. Console.WriteLine(rel(5, 4)); // выводит True
  22. }
  23. }
Success #stdin #stdout 0.01s 29664KB
stdin
Standard input is empty
stdout
True