fork download
  1. using System;
  2.  
  3. namespace Articulos.Preguntas
  4. {
  5. public class UsoThisEnClase
  6. {
  7. private int campo;
  8.  
  9. public UsoThisEnClase(int valor)
  10. {
  11. this.campo = valor;
  12. }
  13.  
  14. public void Metodo(int a)
  15. {
  16. this.campo = a;
  17.  
  18. this = new UsoThisEnClase(9);
  19.  
  20. Console.WriteLine(campo.ToString());
  21. }
  22.  
  23. public static void Main()
  24. {
  25. UsoThisEnClase ut = new UsoThisEnClase(3);
  26.  
  27. ut.Metodo(4);
  28. }
  29. }
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(18,13): error CS1604: Cannot assign to `this' because it is read-only
Compilation failed: 1 error(s), 0 warnings
stdout
Standard output is empty