Int32.Parse Versus Convert.ToInt32 in SharePoint

Today I found out the hard way that SharePoint doesn’t like the function Int32.Parse. I spent several hours trying to debug my code, then finally come to the conclusion that by using Int32.Parse to convert a int to string, it mysteriously prevents execution of everything that follows this line (although this compiles perfectly in VS2008).

The SharePoint correct way to convert int to string is to use the function Convert.ToInt32(myString), btw Convert is also faster than Parse, so I recommend everyone to stop using Parse and use Convert instead even if it is not sharepoint.

2 Responses to “Int32.Parse Versus Convert.ToInt32 in SharePoint”


  • > it mysteriously prevents execution of everything that follows this line

    You were probably passing null to .Parse(), which then throws an exception. Convert.ToInt32() will allow null and just return zero instead.

  • I have been wondering. In which scenario, I should be using (int), Int32.Parse and Convert.ToInt32
    Or are they the same I do notice in certain condition that i cannot cast directly using (int) and I have to use Convert.ToInt32. IT management I am not that sure why i do that. I just need some confirmations from you all.

Leave a Reply