I have just started programming and have an error that I can not fix.
If otherwise error " The <= operator can not be applied to operands of
type "TextBox" and "int").
private void bn_CocaCola_Click(object sender, EventArgs e)
{
int GetränkeWert = 2;
if (tbh_GeldAs <= GetränkeWert)
{
tbh_GeldAs.Text = ("Endnehmen sie Ihr Getränk");
}
else
{
tbh_GeldAs >= GetränkeWert;
tbh_GeldAs.Text = ("Sie müssen Geld einzahlen");
}
}
>Solution :
Error messages are there to help us so try to look at what it is telling you. I looked at the error message in your post and it states that your expression…
tbh_GeldAs <= GetränkeWert
is a comparison of these types.
TextBox <= int.
So what is a textbox? It holds some text but you have to look at the Textbox.Text
property.
tbh_GeldAs.Text <= GetränkeWert
But now this is comparing a string like "123" to an int
and it still doesn’t work! You need to change that string to a number.
Try:
Convert.ToInt32(tbh_GeldAs.Text) <= GetränkeWert
And while I hope this solves your problem, my real answer is to take the time to look at the error message and see what it’s saying because they are usually quite helpful.