fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. var lazy = new SuperLazy<Foo>();
  8. Console.WriteLine(lazy.Value.Bar);
  9. }
  10. }
  11.  
  12. public class Foo
  13. {
  14. public int Bar { get; set; }
  15. public Foo()
  16. {
  17. Bar = 42;
  18. }
  19. }
  20.  
  21. public class SuperLazy<T> : Lazy<T>
  22. where T : new()
  23. {
  24. public SuperLazy()
  25. : base(() => new T())
  26. {
  27. }
  28. }
Success #stdin #stdout 0.02s 14828KB
stdin
Standard input is empty
stdout
42