Problem with inheritance in c #

0

I have the following slogan: Make a programmer view (name, surname, hours worked, button calculate ()) The method calculate returns the result in a programmer view 2 (name, surname - read only). (Time value and incentive in the class as private attribute - to calculate salary: Hour value * Working hours + incentive). I have to make an inheritance between Employee and EmployeeProgrammer.

empleado.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Empresa.Models
{
    public abstract class Empleado
    {
        protected string Nombre { set; get; }
        protected string Apellido { set; get; }
        public Empleado() { }

        public Empleado(string Nombre, string Apellido)
        {
            Nombre = this.Nombre;
            Apellido = this.Apellido;
        }

        /*  public abstract float CalcularSueldo();
          } */

    }
}

EmployeeProgrammer.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Empresa.Models
{
    public class EmpleadoProgramador : Empleado
    {
        private float SueldoFijo { set; get; }

       // public EmpleadoProgramador() { }

        private void EmpleadoProgramador(string Nombre, string Apellido, int horas,float valorHora, float incentivo) : base(Nombre, Apellido)
        {
            horas = 30;
            valorHora = 50;
            incentivo = 5000;
            CalcularSueldo(Nombre, Apellido, horas, valorHora, incentivo);
        }




        public float CalcularSueldo(horas, valorHora, incentivo)
        {

            float SueldoFijo = valorHora * horas + incentivo;
            return SueldoFijo;
        }


    }
}

In private void EmpleadoProgramador(string Nombre, string Apellido, int horas,float valorHora, float incentivo) : base(Nombre, Apellido) it tells me that "the names of the members can not match the enveloping types" and he does not accept me: for the inheritance, he does not accept the CalculateSueldo () method because he says that there is no overload. Also in

public float CalcularSueldo(horas, valorHora, incentivo)
{   

   float SueldoFijo = valorHora * horas + incentivo;
    return SueldoFijo;
}

He tells me that there are no such types. What am I doing wrong?

    
asked by Andrés Oporto 30.04.2017 в 03:43
source

2 answers

1

Good evening kid,

For the "problem": member names can not match the wraparound types , members of a class or structure can not have the same name as the class or structure, Unless the member is a builder, be careful with that. The following method has the same name of the class in this case. If what you want is that this method is a constructor, you must remove the "void" (return value) since a constructor does not return any value:

private void EmpleadoProgramador(string Nombre, string Apellido, int horas,float valorHora, float incentivo) : base(Nombre, Apellido)
    {
        horas = 30;
        valorHora = 50;
        incentivo = 5000;
        CalcularSueldo(Nombre, Apellido, horas, valorHora, incentivo);
    }
    
answered by 30.04.2017 / 09:21
source
0

The error in the public float CalcularSueldo(horas, valorHora, incentivo) method I think is because the definition is wrong. It should be:

public float CalcularSueldo(int horas, float valorHora, float incentivo)

That would be in terms of syntax, to apply inheritance you can use this article: Heritage (Guide to C # programming)

    
answered by 30.04.2017 в 04:02