Implicit type conversion error

0
  

Error 1 Can not implicitly convert type 'CachedCurrent.Customer' to 'string' C: \ course \ CachedCurrent \ CachedCurrent \ Form1.cs 47 31 CachedCurrent

Follow the class

namespace CursoCAvancado
{
    public partial class Form1 : Form
    {
        Conta conta;

        public Form1()
        {
            InitializeComponent();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void Sacar_Click(object sender, EventArgs e)
        {

                double valor = Convert.ToDouble(txtValorSaque.Text);
                this.conta.Saca(valor);
                if (valor < 100)
                {
                    MessageBox.Show("Saque efetuado com sucesso" + this.conta.Saldo);
                }
            }

        private void Form1_Load(object sender, EventArgs e)
        {
            this.conta = new Conta();
            this.conta.Titular = new Cliente("everson");
            this.conta.Numero = 1;
            this.conta.Deposita(100);

            txtNumero.Text = Convert.ToString(this.conta.Numero);
            txtSaldo.Text = Convert.ToString(this.conta.Saldo);
            txtTitular.Text = this.conta.Titular;

        }
     }
}
classe conta
 class Conta
    {
        public int Numero { get; set; }
        public double Saldo { get; set; }
        public Cliente Titular { get; set; }

        public void Saca(double valor) 
        {
            this.Saldo -= valor;
        }
        public void Deposita(double valor) 
        {
            this.Saldo += valor;
        }
        public void Transfere(double valor, Conta destino) 
        {

        }
    }
}

Client Class

public class Cliente
{
    public string Nome { get; set; }

    public Cliente(string nome) 
    {
        this.Nome = nome;
    }
}
    
asked by anonymous 20.11.2014 / 01:29

1 answer

2

The error quotes line 47 from the file. I think it's this:

txtTitular.Text = this.conta.Titular;

If this.conta.Titular is a Cliente , you can not directly assign the value of a text field, which must be a string. To fill in the name of the owner, he failed to get the proper ownership of his Cliente :

txtTitular.Text = this.conta.Titular.Nome;
    
20.11.2014 / 02:52