{"id":130,"date":"2010-12-12T19:55:00","date_gmt":"2010-12-13T01:55:00","guid":{"rendered":"https:\/\/www.chrystalsander.com\/blog\/?p=130"},"modified":"2010-12-12T19:55:00","modified_gmt":"2010-12-13T01:55:00","slug":"parse-vs-convert","status":"publish","type":"post","link":"https:\/\/www.chrystalsander.com\/blog\/?p=130","title":{"rendered":"Parse vs. Convert"},"content":{"rendered":"<p><span style=\"font-style: italic;font-size:85%;\" >(as taken from<a href=\"http:\/\/www.dotnetspider.com\/resources\/1812-Difference-among-Int-Parse-Convert-ToInt.aspx\" target=\"_blank\" rel=\"noopener\"> .NET Spider<\/a>)<\/span><span style=\"font-size:85%;\"><br \/><\/span><br \/>Int32.parse(string)<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>Int32.Parse (string s) method converts the string representation of a number to its 32-bit signed integer equivalent.<br \/>When s is null reference, it will throw ArgumentNullException.<br \/>If s is other than integer value, it will throw FormatException.<br \/>When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException.<\/p>\n<p>Convert.ToInt32(string)<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/>Convert.ToInt32(string s) method converts the specified the string representation of 32-bit signed integer equivalent. This calls in turn Int32.Parse () method.<br \/>When s is null reference, it will return 0 rather than throw ArgumentNullException<br \/>If s is other than integer value, it will throw FormatException.<br \/>When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException<\/p>\n<p>Int32.TryParse(string, out int)<br \/>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<br \/>Int32.Parse(string, out int) method converts the specified the string representation of 32-bit signed integer equivalent to out variable, and returns true if it parsed successfully, false otherwise. This method is available in C# 2.0<br \/>When s is null reference, it will return 0 rather than throw ArgumentNullException.<br \/>If s is other than integer value, the out variable will have 0 rather than FormatException.<br \/>When s represents a number less than MinValue or greater than MaxValue, the out variable will have 0 rather than OverflowException.<\/p>\n<p>Convert.ToInt32 is better than Int32.Parse, since it return 0 rather than exception. But, again according to the requirement this can be used. TryParse will be best since it handles exception itself always.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(as taken from .NET Spider)Int32.parse(string)&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-Int32.Parse (string s) method converts the string representation of a number to its 32-bit signed integer equivalent.When s is null reference, it will throw ArgumentNullException.If s is other than integer value, it will throw FormatException.When s represents a number less than MinValue or greater than MaxValue, it will throw OverflowException. Convert.ToInt32(string)&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-Convert.ToInt32(string &hellip; <a href=\"https:\/\/www.chrystalsander.com\/blog\/?p=130\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Parse vs. Convert&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"_links":{"self":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/130"}],"collection":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=130"}],"version-history":[{"count":0,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chrystalsander.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}