- This topic has 2 replies, 3 voices, and was last updated 8 years, 9 months ago by
Ankur.
- AuthorPosts
- July 8, 2014 at 11:17 am #5009
Pavan
MemberI am developing c# window application then i find these 3 parsing keywords but i am unable to find who is best and where to use?
Please provide me detail with performance wise so i can enhance my application and speed up.September 2, 2014 at 7:20 am #5065Hirendra Sisodiya
KeymasterIn the below I am explaining you in the context of integer.
Suppose you have the string ‘i’ and you use the Int32.Parse method converts the string ‘i’ then the following results will be:
When i is a null reference, it will throw ArgumentNullException.
If i is other than integer value, it will throw FormatException.
When i represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.And now I use the Convert.ToInt32 method then the following results will be:
When ‘i’ is a null reference, it will return 0 rather than throw ArgumentNullException.
If ‘i’ is other than integer value, it will throw FormatException.
When ‘i’ represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.When I use the TryParse method then the results will be:
When ‘i’ is a null reference, it will return 0 rather than throw ArgumentNullException.
If ‘i’ is other than an integer value, the out variable will have 0 rather than FormatException.
When ‘i’ represents a number less than MinValue or greater than MaxValue, the out variable will have 0 rather than OverflowException.thanks
September 2, 2014 at 8:43 am #5066Ankur
MemberSo Should we use TryParse in every scenario to parse a value in Int to prevent any exception ?
- AuthorPosts
- You must be logged in to reply to this topic.