Joe Cool <(E-Mail Removed)> wrote:
> PERFECT! Thank you.
>
> My company is switching from VB to C#.NET so I am practising
> converting some VB.NET apps I wrote for personal use. The more I use
> C# the more I like it, but situations like this ain't helping!!!
>
> VB does a HELL of a lot more implicit datatype conversions and it
> seems I almost have to type EVERY conversion in C#.
Yes. This is a good thing, IMO - it makes it much clearer where
conversions are taking place, which means it's less likely to happen
without you knowing. As Alberto pointed out, with Option Strict On
you'd have had to do the conversion from floating point back to integer
in VB.NET too.
Not all conversions are explicit, of course, and the situation you've
got here is slightly different - there *is* an implicit conversion from
int to double - it's the types used for the *operation* which are
important. The C family of languages (from which C# derives) has always
made / do integer arithmetic when both of the operands are integers.
Note that you only need *one* of the casts to double in the division -
if either operand is a floating point one, floating point division will
be used instead of integer division.
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too