Doubt in the storage of variables

Asked

Viewed 36 times

-1

I’m a beginner in C#, and I’m trying to save the values typed in a toolbox within the property of a Classe, but the code does not compile.

Could someone help me?

Form:

namespace ProgramPrestServico
{
    public partial class Form1 : Form

    {


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {


        }




        private void botaoCadastro_Click_1(object sender, EventArgs e)
        {
            string nomeDigitado = textoNome.Text;
            string telDigitado = textoTel.Text;
            string endDigitado = textoEnd.Text;

            Cliente cliente = new Cliente(nomeDigitado,telDigitado,endDigitado);

            MessageBox.Show("Cadastro de " + Nome + " realizado com sucesso! Confirme os dados. tel: " + Tel + " End: " + End);
        }

    }
}

Customer class

    namespace ProgramPrestServico

    public class Cliente
    {
        public Cliente(string nome, string tel, string end)
        {
            this.Nome = nome;
            this.Tel = tel;
            this.End = end;
        }
        public string Nome { get; set; }
        public string Tel { get; set; }
        public string End { get; set; }
    }

}
  • Which message the compiler returns?

1 answer

3


The code of MessageBox does not make sense. There are no variables Nome, Tel and End.

The variables are nomeDigitado, telDigitado and endDigitado.

The code should be

MessageBox.Show("Cadastro de " + nomeDigitado + " realizado com sucesso! Confirme os dados. tel: " + telDigitado + " End: " + endDigitado);

If you want the properties of Cliente, it must be so

MessageBox.Show("Cadastro de " + cliente.Nome + " realizado com sucesso! Confirme os dados. tel: " + cliente.Tel + " End: " + cliente.End);
  • 1

    It may want to use the attributes of the Client: client class. Name, client.Tel ....

  • Now yes I understand. I was forgetting to reference the customer class. Thank you very much

  • @Thank you, I hadn’t noticed.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.