fork download
  1. using System;
  2.  
  3. public class Program {
  4. public static void Main() {
  5. var obj = new MinhaClasse();
  6. obj.Idade = 20;
  7. Console.WriteLine(obj.Idade);
  8. obj.Idade = 10;
  9.  
  10. }
  11. }
  12.  
  13. public class MinhaClasse {
  14. private int idade;
  15. public int Idade {
  16. get => idade;
  17. set => idade = value < 18 ? throw new Exception("Proibido para menores!") : value;
  18. }
  19. }
  20.  
  21. //https://pt.stackoverflow.com/q/263498/101
Runtime error #stdin #stdout #stderr 0.02s 16112KB
stdin
Standard input is empty
stdout
20
stderr
Unhandled Exception:
System.Exception: Proibido para menores!
  at MinhaClasse.set_Idade (System.Int32 value) [0x0001f] in <be37564794bf476db1a1b275e7431200>:0 
  at Program.Main () [0x00019] in <be37564794bf476db1a1b275e7431200>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.Exception: Proibido para menores!
  at MinhaClasse.set_Idade (System.Int32 value) [0x0001f] in <be37564794bf476db1a1b275e7431200>:0 
  at Program.Main () [0x00019] in <be37564794bf476db1a1b275e7431200>:0