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

Hi, I'm using VS2013, C# and 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.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Daniel Van Der WerkenIndependent ConsultantCommented:
It would help if we had a little of your code to see how the return is handled.

Short answer: I don't know. Long answer: Here are some things you can do:

object myMostExcellentInteger = 5;
int myInteger = int.MinValue;

if (int.TryParse(myMostExcellentInteger.ToString(), out myInteger))
     // Run some excellent code

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
David Johnson, CD, MVPOwnerCommented:
Enter an Integer
Not a Number
Conversion from string "a" to type 'Integer' is not valid.
This is VB but you have to validate all user input.
Imports System
Module Module1
    Sub Main()
        Dim i As Integer
        Console.WriteLine("Enter an Integer")
            i = Console.ReadLine()
        Catch ex As Exception
            Console.WriteLine("Not a Number" & vbCrLf & ex.Message)
        End Try
    End Sub
End Module

Open in new window

lapuccaAuthor Commented:
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?
Daniel Van Der WerkenIndependent ConsultantCommented:
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.
lapuccaAuthor Commented:
Not exactly the same but okay.  Thank you both.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.