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.

1 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.

Leave a Reply