Last active
December 25, 2015 05:49
-
-
Save Fhernd/6926687 to your computer and use it in GitHub Desktop.
Demostración de la accesbilidad de get y set en C#.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace PruebaAccesibilidad | |
{ | |
public class Empleado | |
{ | |
private string nombre; | |
public Empleado(string nombre) | |
{ | |
this.nombre = nombre; | |
} | |
public string Nombre | |
{ | |
get | |
{ | |
return nombre; | |
} | |
private set | |
{ | |
nombre = value; | |
} | |
} | |
} | |
public class PruebaEmpleado | |
{ | |
public static void Main () | |
{ | |
Empleado empleado = new Empleado ("Edgar"); | |
empleado.Nombre = "Melissa"; // se generará error en tiempo de compilación | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment