Cannot implicity Convert type int to string?

Asked

Viewed 57 times

2

I am here copying a tutorial and is giving an error that I am not able to solve.

Error:

cannot implicity Convert type int to string

Code:

    label_nome.Text = "Funcionario" + num_funcionario;
    count_idade.Value = 18;
}
private void cmd_contratar_Click(object sender, EventArgs e)
{
    FUNCIONARIOS.Add(new cl_funcionario() { 
        nome = label_nome.Text, 
        idade = (int)count_idade.Value // Erro 
    });
    num_funcionario++;
}
  • 2

    I would say that num_funcionario is a int and you’re trying to concatenate him with a String. It would not be the case to do num_funcionario.ToString()?

  • 1

    We need you to provide the class and adjust the text as I did in the edition, this cast is invalid, but where he’s going I also don’t know what he gets, it’s all complicated if I don’t post the related items. As was said a ToString() can solve, but, if the problem is bigger and there is no way to know.

  • that’s right thank you

  • 1

    Be careful not to make unnecessary conversions, careful I think you are going the wrong way.

1 answer

3


I believe you are trying to concatenate an int with a string

label_nome.Text = "Funcionario" + num_funcionario.ToString();

that should solve

Browser other questions tagged

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