I want to know if it is a number or letter the textbox that you enter by keyboard
if (txtCodigo.Text) { MessageBox.Show("son numeros"); } else { MessageBox.Show("son letras"); }
I want to know if it is a number or letter the textbox that you enter by keyboard
if (txtCodigo.Text) { MessageBox.Show("son numeros"); } else { MessageBox.Show("son letras"); }
You could implement something like being
int temp = 0;
if (int.TryParse(txtCodigo.Text, out temp))
{
MessageBox.Show("son numeros");
}
else
{
MessageBox.Show("son letras");
}
when you try to parse to numeric the TryParse()
returns a true / false that you can use to know if it is a valid number or not
You can use TryParse
to see if the entire conversion of the text is possible. If it is, it is a numerical value. If not, text:
int valorNumerico = 0;
if (int.TryParse(txtCodigo.Text,out valorNumerico))
{
//numero
}
else
{
//no numero
}