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

Recommended Answers

All 6 Replies

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.

Pleas send me code for example THANKs

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.

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

Convert strings into integers and then do the comparison:

int intValueA = Convert.ToInt32(txtMath.Text);
if (ibtValueA >= 80)
commented: 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");
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.