Link to home
Start Free TrialLog in
Avatar of lapucca
lapucca

asked on

Do I need to further validate an int variable return to my from an api?

Hi, I'm using VS2013, C# and asp.net web form
I use Server.HtmlEncode for all the strings type of variable that I got back from calling 3rd party api.  What if the return type if int, can I just count on C# being strong type and would take care of that or do I need to do further validation and how?  
Thank you.
ASKER CERTIFIED SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lapucca
lapucca

ASKER

The 3rd party returns an object that I instantiated.  All values returned are stored in this object's property.  I think your example code is good enough.  But my question is also that if this property type is of "int" type then do I still need to check using your example?  I mean, C# is strong type so wouldn't it already throw an exception if I'm getting non-integer or script embedded value in an int property field?
I think that's what David Johnson is showing you. If the value returned isn't an integer, then you'll get an exception. Make sure you handle the exception, though.
Avatar of lapucca

ASKER

Not exactly the same but okay.  Thank you both.