0

if (txtMath.text >= "90")

lblgrad.Text = "A+";
else
if (txtMath.Text >= "80")
lblgrad.Text = "A";
else if (txtMath.Text >= "70")
lblgrad.Text = "B";
else if (txtMath.Text == "60")
lblgrad.Text = "c";
else if (txtMath.Text == "50")
lblgrad.Text = "D";
else if (txtMath.Text == "50")
MessageBox.Show ("You are failed in your exaim");
======================================================================================
It give error as below
//Error 1 Operator '>=' cannot be applied to operands of type //'string' and 'string'

Pleas help me in this matter as soon as possible

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by ddanbe
Featured Replies
  • Convert strings into integers and then do the comparison: [CODE] int intValueA = Convert.ToInt32(txtMath.Text); if (ibtValueA >= 80)[/CODE] Read More

0

Strings can only be compared this way with the != and == operators.
If you want to use greater than or less than, use the string Compare method.

0
string A = "60";
string B = "80";
int i = A.CompareTo(B);

A < B returns -1
A = B returns 0
A > B returns 1
So in the code snippet above i will be equal to -1, because string A is "smaller" then string B.

Edited by ddanbe: n/a

0

But how i apply this code at my

txtmath.text

i have one text box called txtmath and i want use grade.which marks user enter example

user enter 60 in txtmath.text
how can i use it that

if(txtmath >60)
messagebox.show("you have gotten A+ grade);
pleas help me as I requested

1

Convert strings into integers and then do the comparison:

int intValueA = Convert.ToInt32(txtMath.Text);
if (ibtValueA >= 80)

Edited by Mitja Bonca: n/a

Votes + Comments
THIS IS BEST SOLVED
0

You should follow the idea of Mitja, which is the most obvious way to do such things.
But to answer your question you could do a thing like:

i = txtmath.text.CompareTo("80");
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.