3
I’m putting together a script of fighters, the category I want to be a private method and that it is according to the weight that the user type, but I’m not able to mix these two attributes in the function. Category: string and weight: double.
The code generates error in the constructor, when I call the set function of the category attribute.
class Lutador
    {
        private string _categoria;
        public string Nome { get; set; }
        public double Peso { get; set; }
        public Lutador(string nome, double peso)
        {
            Nome = nome;
            Peso = peso;
            //Erro
            Categoria = Peso;
        }
        public string Categoria
        {
            get { return _categoria; }
            set
            {
                if (Peso <= 50.0)
                {
                    _categoria = "leve";
                }else if (Peso <= 80.0)
                {
                    _categoria = "médio";
                }
                else
                {
                    _categoria = "pesado";
                }
            }
    } 
}
Helped too much, I understood your logic well, I also liked the line of reasoning.
– Felipe Arruda
Another alternative would be to create a
getto theCategoriato generate the valuesleve,medioandpesadojust when you access the property. I think it would be more concise that way.– Andre