fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. static void Main(string[] args)
  6. {
  7. Foo(5, () => gt);
  8.  
  9. Console.ReadKey();
  10. }
  11.  
  12. private static int gt
  13. {
  14. get
  15. {
  16. Console.WriteLine("чтение переменной");
  17. return 100;
  18. }
  19. }
  20.  
  21. static void Foo(int z, Func<int> getData)
  22. {
  23. Console.WriteLine("метод");
  24. if (z >= 10)
  25. {
  26. Console.WriteLine("переменная больше 10");
  27. }
  28. else
  29. {
  30. Console.WriteLine("переменная = " + getData());
  31. }
  32. }
  33. }
Success #stdin #stdout 0.01s 131648KB
stdin
Standard input is empty
stdout
метод
чтение переменной
переменная = 100