{"id":8138,"date":"2020-04-29T21:03:31","date_gmt":"2020-04-29T21:03:31","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8138"},"modified":"2020-04-29T21:03:31","modified_gmt":"2020-04-29T21:03:31","slug":"so-_-are-called-discards","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/so-_-are-called-discards\/","title":{"rendered":"So _ are called discards"},"content":{"rendered":"<p>I&#8217;ve used the _ (underscore) previously in code &#8211; particularly with F# tuples but also C#. It is used to denote a value that is intentionally unused, ignored, discarded.<\/p>\n<p>It seems that the underscore used in such situations has a name (maybe it has the same name in other languages, I&#8217;ve not yet checked). It&#8217;s called a <strong>discard<\/strong>.<\/p>\n<p><em>Note: With regard to its use in C#, it appeared with C# 7.0.<\/em><\/p>\n<p>Let&#8217;s have a look at a very simple example<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic bool IsNumber =&gt; Double.TryParse(&quot;123&quot;, out _);\r\n<\/pre>\n<p>This slightly contrived example (the best I could think of quickly) shows how this might be used. In this example we&#8217;re not interested in the <em>out<\/em> value so just use a <strong>discard<\/strong> to basically say &#8220;this is unused, ignore it&#8221;.<\/p>\n<p><em>Note: The discard doesn&#8217;t need a <em>var<\/em> or type.<\/em><\/p>\n<p>Obviously the discard comes in very useful with tuples. I guess, for C#, this became most useful when tuples became a first class language feature. <\/p>\n<p>So for example we might have this code<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\npublic (string, string, int) GetPerson()\r\n{\r\n   return (&quot;Scooby&quot;, &quot;Doo&quot;, 13);\r\n}\r\n\r\n\/\/ in use we only want the age\r\nvar (_, _, age) = GetPerson();\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve used the _ (underscore) previously in code &#8211; particularly with F# tuples but also C#. It is used to denote a value that is intentionally unused, ignored, discarded. It seems that the underscore used in such situations has a name (maybe it has the same name in other languages, I&#8217;ve not yet checked). It&#8217;s [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[49,3],"tags":[],"class_list":["post-8138","post","type-post","status-publish","format-standard","hentry","category-net","category-c"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8138","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8138"}],"version-history":[{"count":2,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8138\/revisions"}],"predecessor-version":[{"id":8145,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8138\/revisions\/8145"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8138"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8138"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8138"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}