Clase Empleado

 class Empleado
    {
        private string pNombre;
        private string pDni;
        private decimal pSueldo;

        public string Nombre
        {
            get
            {
                return pNombre;
            }
            set
            {
                    Console.WriteLine("Set de nombre");
                if (value.Length < 3)
                {
                    throw new Exception("El nombre debe tener una longitud mayor de 3");
                }
                else
                {
                    this.pNombre = value;
                }
            }
        }
        public string Dni
        {
            get { return this.pDni; }
            set { this.pDni = value; }
        }
        public decimal Sueldo
        {
            get { return this.pSueldo; }
            set { this.pSueldo = value; }
        }
        public Empleado(string nombre)
        {
            Console.WriteLine("Constructor 1");
            this.Nombre = nombre;
        }
        public Empleado(string nombre, string dni) : this(nombre)
        {
            Console.WriteLine("Constructor 2");
            this.Dni = dni;
        }
        public Empleado(string nombre, string dni, decimal sueldo) : this(nombre, dni)
        {
            Console.WriteLine("Constructor 3");
            this.Sueldo = sueldo;
        }
    }

Publicado por

Avatar del usuario

Juan Pablo Fuentes

Formador de programación y bases de datos