Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Casting a VFP numeric field
Message
 
À
30/03/2009 18:24:40
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01392244
Message ID:
01392377
Vues:
45
>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).
-Paul

RCS Solutions, Inc.
Blog
Twitter
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform