.NET Hawa

Performace Grading in Integer Conversions

on December 20, 2011

  As we are working with .Net, libraries will also have similar meathods for perform single operation we need to know what is the better one and what is a big one. I searched over internet and here i am explaining giving information about some known meathods, Integer.Parse(), Convert.ToInt32(),Integer.TryParse().


Integer.Parse() method should have argument as String datatype. It will parse the string for integer value. If it has no integer value or it contains mixture of integer and characters it will throw you a exception.


Integer.Parse(string S)


Integer.TryParse takes arugments as string and an Integer. This fucntion will return boolean value. This function will work same as Integer.Parse() but it will not throw any exception. If string does not contains any integer value it will return false.

Integer.TryParse(String S, Out Integer I)


This will work as same as Integer.Parse(). So I am not explaining more about this. Convert.Toint32() aceepts null as a argumnet. Integer.Parse() will accept. Convert.ToInt32() internally calls Integer.Parse()

The main difference is taking out with the performance

Integer.TryParse() > Convert.Toint32() > Integer.Parse()

Because Integer.Parse() will throws exception when it has string or null value. Convert.toInt32() check for null string if it is null it will directly throw exception and if it is not null it will call integer.parse() meathod. Integer.TryParse() will try to parse all values and returns boolean values.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: