Please help me with the following code

N

NotYetaNurd

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";
 
M

Morten Wennevik

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.
 
N

NotYetaNurd

i tried this
((withdrawal-expence)> 0.0F)?

but still

Cannot implicitly convert type 'string' to 'bool'






Morten Wennevik said:
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.
 
M

Morten Wennevik

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";
 
G

Guest

NotYetaNurd said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top