Difference between Int32.Parse,Convert.Int32

Int32.Parse Method:-------------------Converts the string representation of a number to its 32-bit signed integer equivalent.-When s is a null reference, it will throw ArgumentNullException.-If s is other than integer value, it will throw FormatException.-When s represents a number out of range, it will throw OverflowException.

Convert.ToInt32(string):-------------------------Converts the specified string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.-When s is a null reference, it will return 0 rather than throw ArgumentNullException.-If s is other than integer value, it will throw FormatException.-When s represents a number out of range, it will throw OverflowException.

Int32.TryParse Method:----------------------Converts the specified string representation of 32-bit signed integer equivalent to out variable, and returns true if it is parsed successfully, false otherwise.-When s is a null reference, it will return 0.-If s is other than an integer value, the out variable will have 0.-When s represents a number out of range, the out variable will have 0.

You can also find related Interview Question to
Difference between Int32.Parse,Convert.Int32
below:

Parse method throws an exception if the string you are trying to parse is not a valid number where as TryParse returns false and does not throw an exception if parsing fails. Hence TryParse is more efficient than Parse (More...)

Parse method is used to parse any value to specified data type. TryParse is a good method if the string you are converting to an integer is not always numeric. The TryParse method returns a boolean to denote whether the conversion has been successfull or not, and returns the converted value through an out parameter. (More...)

The main difference between ToString() and Convert.ToString() is,"Convert" function handles NULLS while "variable.ToString()" does not it will throw a NULL reference exception error. So as a good coding practice using "convert" is always safe.

.Delete table is a logged operation, so the deletion of each row gets logged in the transaction log, which makes it slow.

. Truncate table also deletes all the rows in a table, but it won't log the deletion of each row, instead it logs the de-allocation of the data pages of the table, which makes it faster. Of course, truncate table cannot be rolled back.

. Truncate table is functionally identical to delete statement with no "where clause" both remove all rows in the table. But truncate table is faster and uses fewer system and transaction log resources than delete.

. Truncate table removes all rows from a table, but the table structure and its columns, constraints, indexes etc., remains as it is.

. In truncate table the counter used by an identity column for new rows is reset to the seed for the column.

. If you want to retain the identity counter, use delete statement instead.

. If you want to remove table definition and its data, use the drop table statement.

. You cannot use truncate table on a table referenced by a foreign key constraint; instead, use delete statement without a where clause. Because truncate table is not logged, it cannot activate a trigger.

. Truncate table may not be used on tables participating in an indexed view. (More...)

Find questions, FAQ's and their answers related to .NET, C#, Vb.Net, Sql Server and many more.

Now you can find lots of .NET, C#, Vb.Net, SQL Server,Windows, ASP.Net related Questions and their Answers here at www.dotnetspark.com. Our aim is to help you pass your certification Exams (MCP, MCSD, MCAD etc.,) with flying scores and get good name in your company.

So, Start looking our Interview Question section daily and improve your .NET Skills. You can also help others by posting Interview Questions and their Answers in this section.