fork download
  1. using System;
  2.  
  3. public class Propertier {
  4. public string ReadOnlyPlease { get; private set; }
  5.  
  6. public Propertier() { ReadOnlyPlease="As initialised"; }
  7. public void Method() { ReadOnlyPlease="This might be changed internally"; }
  8. public override string ToString() { return String.Format("[{0}]",ReadOnlyPlease); }
  9. }
  10.  
  11. public class Program {
  12. static void Main() {
  13. Propertier p=new Propertier();
  14. Console.WriteLine(p);
  15.  
  16. // p.ReadOnlyPlease="Changing externally!";
  17. // Console.WriteLine(p);
  18.  
  19. // error CS0272: The property or indexer `Propertier.ReadOnlyPlease' cannot be used in this context because the set accessor is inaccessible
  20. // That's good and intended.
  21.  
  22. // But...
  23. p.Method();
  24. Console.WriteLine(p);
  25. }
  26. }
Success #stdin #stdout 0.03s 33840KB
stdin
Standard input is empty
stdout
[As initialised]
[This might be changed internally]