Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Casting a VFP numeric field
Message
From
31/03/2009 11:18:36
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01392244
Message ID:
01392384
Views:
36
>>Hi Gerard
>>Because I think you are dealing with an object even though you might have an int in the underlying field. using (int) is an implicit cast and does not work with objects.
>>Tim
>
>That's not really the case. An implicit cast happens automatically - the compiler does the cast for you based on it's internal casting rules.
>
>This is an implicit cast:
>
>
>int myNum = 5;
>decimal newNum = myNum;
>
>
>Convert.ToInt32() can accept objects, strings, bytes, decimals, chars, etc. and it will still successfully convert it.
>
>An explicit cast, like:
>
>
>object myNum = 7;
>int result = (int)myNum;
>
>
>Only works when the underlying cast is valid (and is only evaluated at runtime). The compiler assumes you know what you're doing. So, the most likely reason Convert.ToInt32() is working here is the underlying type in the row isn't actually an Int, but some other number type (or even string).

Yes, I see I didn't really type that right; should have said explicit rather than implicit. I saw from a later post of his the num field he had wasn't really an int as you mentioned which I suspected.
Thanks for setting me straight Paul.
Tim
Timothy Bryan
Previous
Reply
Map
View

Click here to load this message in the networking platform