Converting string to int using TryParse

Datatype int is a very commonly used in .Net applications. We may face a situation where we need to convert string into int.

.Net has provided many methods for converting string to int. We will use TryParemethod to convert string to int. As TryParse method doesn’t throw exception if string cannot be converted to int.

Return value of this method is bool which indicates whether conversion was successful or not.

string MarksObtained = "90";
int Marks = 0;
bool Converted = int.TryParse(MarksObtained, out Marks);

Comments

Popular posts from this blog

Check if ViewBag is null or doesn't exist

Using Progress Bar In C#

Jquery serer side datatables in asp.net