Thursday, February 22, 2018

Difference between Various Parse in C#

C# supports 3 supported Parse function:
1) int.Parse(stringTobeParsed...);
2) int.TryParse (stringTobeParsed, out intVariableToCatchResult) : int
3) Convert.ToInt(...)


Out of these 3, the most preferred one is 2nd one i.e TryParse which doesn't throw exceptions like other 2 and based on it's return value, one can understand whether conversion is success or not. i.e we should process the out value only when this function returns true. When exception stuff exist in input params, it returns false.


Reference:


https://www.codeproject.com/Tips/845439/Difference-between-int-Parse-Convert-ToInt-and-int

No comments: