fork download
  1. using static System.Console;
  2.  
  3. public class Test {
  4. public static void Main() {
  5. Teste teste = new Teste();
  6. //teste.array = new int[5];
  7. teste.array[0] = 1;
  8. teste.Array = new int[5];
  9. WriteLine(teste.Array.Length);
  10. teste.Array = new int[4];
  11. WriteLine(teste.Array.Length);
  12. }
  13. }
  14.  
  15. public class Teste {
  16. public readonly int[] array = new int[4];
  17. private int[] array2 = new int[4];
  18. public int[] Array { get => array2; set {
  19. if (value.Length == 4) array2 = value;
  20. //decide se quer gerar uma exceção no else
  21. }
  22. }
  23. }
  24.  
  25. //https://pt.stackoverflow.com/q/570019/101
Success #stdin #stdout 0.03s 22224KB
stdin
Standard input is empty
stdout
4
4