fork download
  1. using System;
  2.  
  3. public class Base
  4. {
  5. public virtual string Foo { get; }
  6.  
  7. public Base()
  8. {
  9. Console.WriteLine("Base()");
  10. Foo = "value from Base()";
  11. Console.WriteLine($"Foo = {Foo}");
  12. }
  13. }
  14. public class Derived : Base
  15. {
  16. public override string Foo { get; } = "value from Derived init";
  17. }
  18.  
  19. public class Test
  20. {
  21. public static void Main()
  22. {
  23. Base x = new Derived();
  24. Console.WriteLine($"main: {x.Foo}");
  25. }
  26. }
Success #stdin #stdout 0.04s 23984KB
stdin
Standard input is empty
stdout
Base()
Foo = value from Derived init
main: value from Derived init