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
Post a Comment