Ah, yes that would make sense.
In this particular case variable2 is an enum, which according to the
documentation is stored by default as an integer. It would seem the
casting/conversion is rather cosmetic (to satisfy the compiler strong
typing).
So, what about this specific case? Any difference between the two and why?
But more generally speaking, I was really thinking only about between number
types - conversions from strings are a whole nutter ball game in my opinion.
Does your answer still depend on the two numeric types (assuming for the
sake of this discussion we're talking only about widening conversions)?
"Jon Skeet" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Daniel Billingsley <db**********@NO.durcon.SPAAMM.com> wrote: Is there any significant difference between
int variable1 = (int) variable2;
and
int variable1 = Convert.ToInt32(variable2);
Absolutely. However, the exact difference will depend on the type of
variable2.
For instance, if variable2 has a value which is a string reference to
"23" then Convert.ToInt32 will parse the int. However, you can't *cast*
from a string to an int.
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too