Type Conversion Question

  • Thread starter Thread starter Paul Hetherington
  • Start date Start date
P

Paul Hetherington

Hi,
Which is the more recomended way to do type conversion in C# for basic data
types(integer, singles, doubles etc...)
System.Convert.ToSingle,ToInt32 etc...?
or (float)myvar; (int)myvar, etc..?

TIA
 
In the first case, the runtime does the conversion for you. In the second
case, the compiler does the conversion. Where possible, if left to me, I'll
let the compiler do these kind of basic type conversions - because it's done
once during compile phase and makes my code snappier.

-vJ
 
Back
Top