469,354 Members | 2,485 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,354 developers. It's quick & easy.

Please help me with the following code

Please help me with the following snippet
float withdrawal=(objgetWithdrawal is float)? (float)objgetWithdrawal :0;

float expence= (objgetSpending is float)? (float)objgetSpending :0;

lblBal.Text="Current Balance = Rs." +

(withdrawal-expence) > 0.0F? //here i am getting the error "Operator '>'
cannot be applied to operands of type 'string' and 'float'"
(withdrawal-expence).ToString():"Error Check DB";
Nov 16 '05 #1
4 981
Hi NotYetaNurd

Put a ().ToString() around your float test, or possibly just a (). The compiler thinks you are trying to do ("Current Balance = Rs." + (withdrawal-expence)) > 0.0F, which will turn out to be string > float.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
i tried this
((withdrawal-expence)> 0.0F)?

but still

Cannot implicitly convert type 'string' to 'bool'


"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr9sesxpgklbvpo@morten_x.edunord...
Hi NotYetaNurd

Put a ().ToString() around your float test, or possibly just a (). The compiler thinks you are trying to do ("Current Balance = Rs." +
(withdrawal-expence)) > 0.0F, which will turn out to be string > float.
--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3
Well, your line is missing information

<statement> ? <if true> : <if false>

((withdrawal-expence)>0.0F) will be bool(ean) true or false. You are missing the information to be written.

((withdrawal-expence)>0.0F) ? "Still money left" : "Sorry dude, you spent more than you had";

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
"NotYetaNurd" wrote:
Please help me with the following snippet
float withdrawal=(objgetWithdrawal is float)? (float)objgetWithdrawal :0;

float expence= (objgetSpending is float)? (float)objgetSpending :0;

lblBal.Text="Current Balance = Rs." +

(withdrawal-expence) > 0.0F? //here i am getting the error "Operator '>'
cannot be applied to operands of type 'string' and 'float'"
(withdrawal-expence).ToString():"Error Check DB";


put () around the whole thing might solve it

( (withdrawal-expence) > 0.0F? (withdrawal-expence).ToString():"Error Check DB" )

I think as a good practice, you should really stop cramming so much into a single line. it's bad for readability, a maintainence nightmare months down the line and likely to be buggie. for example, sometimes (when you don't have the right grouping), implicit conversions could cause lines like this to evaluate to something very different from your original intension without generating errors. this is definitely not the right way to obfuscate code.
Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.