|
|
 |
Re: FN-FORUM: C# Help
date posted 8th February 2008 21:47
> Phillip Healey wrote:
>> Hi,
>>
>> Im tinkering with a tutorial / sample code which was given in VB.Net, and
>> i have converted into c#. However i keep getting an error with this code:
>>
>> if ((int.Parse(intCurrIndex.Text) + (1 <
>> int.Parse(intRecordCount.Text))))
>> {
>> intCurrIndex.Text = ((int.Parse(intCurrIndex.Text) +
>> int.Parse(intPageSize.Text))).ToString();
>> }
>>
>> The error says: Operator '+' cannot be applied to operands of type
>> 'short' and 'bool'
>>
>> Can anyone help me format / rectify this.
>>
> Gary short wrote:
> The result of the first parenthesis is a number (you converted the text to
> an int) and then you are trying to add it to the contents of the second
> parenthesis which is a bool (is 1 less than the result of turning the text
> into a number) so that is never going to work. if you want to do addition
> then both sides of the + operator have to be of a number type. What is it
> that you are actually trying to do?
>
Hi,
The reason for the error is exactly as Gary stated in his response above.
Because the second part of your IF statement checks for a value of
"intRecordCount > 1" I would guess that the "+" (which you can use for
adding numbers in C#) should probably be "&&" (which means AND). If this is
the case then the first part of the IF statement also needs to give a
boolean answer (True or False) and not purely a number. For example the
first part could read "int.Parse(intCurrIndex.Text) > 0" (greater than zero)
or "int.Parse(intCurrIndex.Text) != 0" (not equal zero). So, changing the
first part of the IF statement to return a boolean and the "+" to a "&&"
will remove the error, but you'll need to check if it provides you with the
expected result.
It really does depend what the code is trying to do, but hopefully this
helps.
cheers,
Dudley
Dudley Trueman
www.truecreations.co.uk
|
 |
|