Share via


Operator '>' cannot be applied to operands of type 'string' and 'string'

Question

Sunday, September 27, 2009 3:32 AM

How to compare the character value of LabelText9 which is string.

if (book1.LabelText9 > book2.LabelText9)
        {
            LabelCompare.Text = book2;
        }
        else
        {
            LabelCompare.Text = book1;
        }

Please help me with this ...

Thanks

<input id="gwProxy" type="hidden"><!--Session data--><input onclick="jsCall();" id="jsProxy" type="hidden">

All replies (2)

Sunday, September 27, 2009 5:04 AM ✅Answered

Hi,

use CompareTo

ex: if (book1.LabelText9.CompareTo(book2.LabelText9) > 0)


Tuesday, September 29, 2009 3:10 AM ✅Answered

If book.LabelText9 and book2.LabelText9 contain integer values then type cast them into the right type and then apply the '>' operator.

Convert.ToInt32(book1.LabelText9) > Convert.ToInt32(book2.LabelText9).

But if you are trying to check the length of the text in these two labels then try book1.LabelText9**.Length**.

book1.LabelText9**.Length >** book2.LabelText9**.Length**

If you are checking for the characters as in if("book" > "Book") then I suggest you to use CompareTo string operator.