fork download
  1. using System;
  2. using static System.Console;
  3.  
  4. public class Program {
  5. public static void Main() {
  6. var teste = new Teste(1, "abc");
  7. WriteLine(teste.a);
  8. WriteLine(teste.c);
  9. var teste2 = new Teste();
  10. WriteLine(teste2.a);
  11. WriteLine(teste2.c);
  12. var teste3 = new Teste(15) { a = 2, c = "xxx".ToCharArray() };
  13. WriteLine(teste3.a);
  14. WriteLine(teste3.c);
  15. var teste4 = new Teste(1, "abc123456789012345678901234567890");
  16. }
  17. }
  18.  
  19. struct Teste {
  20. public int a;
  21. public char[] c;
  22. public Teste(int size = 30) {
  23. if (size > 30) throw new ArgumentException($"parâmetro deve ter tamanho máximo de 30");
  24. a = 0;
  25. c = new char[size];
  26. }
  27. public Teste(int a, char[] c) {
  28. if (c.Length > 30) throw new ArgumentException($"parâmetro para {nameof(c)} deve ter tamanho máximo de 30");
  29. this.a = a;
  30. this.c = c;
  31. }
  32. public Teste(int a, string c) : this(a, c.ToCharArray()) {}
  33. }
  34.  
  35. //https://pt.stackoverflow.com/q/106470/101
Runtime error #stdin #stdout #stderr 0.02s 15808KB
stdin
Standard input is empty
stdout
1
abc
0

2
xxx
stderr
Unhandled Exception:
System.ArgumentException: parâmetro para c deve ter tamanho máximo de 30
  at Teste..ctor (System.Int32 a, System.Char[] c) [0x00019] in <3dd6255e519a4a3f903660622d4a8fdf>:0 
  at Teste..ctor (System.Int32 a, System.String c) [0x00008] in <3dd6255e519a4a3f903660622d4a8fdf>:0 
  at Program.Main () [0x00080] in <3dd6255e519a4a3f903660622d4a8fdf>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.ArgumentException: parâmetro para c deve ter tamanho máximo de 30
  at Teste..ctor (System.Int32 a, System.Char[] c) [0x00019] in <3dd6255e519a4a3f903660622d4a8fdf>:0 
  at Teste..ctor (System.Int32 a, System.String c) [0x00008] in <3dd6255e519a4a3f903660622d4a8fdf>:0 
  at Program.Main () [0x00080] in <3dd6255e519a4a3f903660622d4a8fdf>:0