{"id":519,"date":"2003-10-03T16:30:54","date_gmt":"2003-10-03T20:30:54","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=519"},"modified":"2003-10-03T16:30:54","modified_gmt":"2003-10-03T20:30:54","slug":"more-on-the-out-method-parameter","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2003\/10\/03\/more-on-the-out-method-parameter\/","title":{"rendered":"More on the out method parameter"},"content":{"rendered":"<p>I&#8217;m sure this is boring for about 99% of you, but I&#8217;m writing for my own benefit anyway.  I mentioned the &#8216;out method parameter&#8217; yesterday because I saw it used in a custom library I&#8217;m using and then today I found out that the <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfSystemDoubleClassTopic.asp\">Double<\/a> class uses it as well. I think it&#8217;s a great example of how it should be used. It&#8217;s used in the <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfSystemDoubleClassTryParseTopic.asp?frame=true\">TryParse<\/a> method:<\/p>\n<p>public static bool TryParse(<br \/>\n&nbsp;&nbsp;&nbsp;<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemstringclasstopic.asp\">string<\/a> s,<br \/>\n&nbsp;&nbsp;&nbsp;<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemglobalizationnumberstylesclasstopic.asp\">NumberStyles<\/a> style,<br \/>\n&nbsp;&nbsp;&nbsp;<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/cpref\/html\/frlrfsystemiformatproviderclasstopic.asp\">IFormatProvider<\/a> provider,<br \/>\n&nbsp;&nbsp;&nbsp;out double result<br \/>\n);<\/p>\n<p>&#8220;<i>The TryParse method is like the Parse method, except this method does not throw an exception if the conversion fails. If the conversion succeeds, the return value is true and the result parameter is set to the outcome of the conversion. If the conversion fails, the return value is false and the result parameter is set to zero.<\/i>&#8221;<\/p>\n<p>I like it because throwing an exception (ie: what the Parse() method does) violates rule #39 of <a href=\"http:\/\/java.sun.com\/docs\/books\/effective\/\">Effective Java Programming<\/a> which says to &#8220;&#8230;  Use exceptions only for exceptional conditions.&#8221;  Using an out parameter feels cleaner and simpler.  Anyone else think so?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m sure this is boring for about 99% of you, but I&#8217;m writing for my own benefit anyway. I mentioned the &#8216;out method parameter&#8217; yesterday because I saw it used in a custom library I&#8217;m using and then today I found out that the Double class uses it as well. I think it&#8217;s a great &hellip; <a href=\"https:\/\/cephas.net\/blog\/2003\/10\/03\/more-on-the-out-method-parameter\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">More on the out method parameter<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[17],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/519"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=519"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/519\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}