Please help me with the following code

  • Thread starter Thread starter NotYetaNurd
  • Start date Start date
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";
 
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.
 
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.
 
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";
 
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.
 
Back
Top