{"id":430,"date":"2019-12-01T20:24:47","date_gmt":"2019-12-01T20:24:47","guid":{"rendered":"http:\/\/paradysz.pl\/?p=430"},"modified":"2019-12-01T20:24:49","modified_gmt":"2019-12-01T20:24:49","slug":"programming-riddle-2","status":"publish","type":"post","link":"https:\/\/paradysz.pl\/index.php\/2019\/12\/01\/programming-riddle-2\/","title":{"rendered":"Programming Riddle 2"},"content":{"rendered":"\n<p class=\"justify-text\">It is the turn of programming riddle number 2. Now, it is dedicated to developers who coding in C#. <\/p>\n\n\n\n<p class=\"justify-text\">So, the question is &#8211; what is the output of the following code:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nvar actions = new List&lt;Func&lt;int&gt;&gt;();\nvar iterator = 0;\n\nwhile (iterator &lt; 10)\n{\n    actions.Add(() =&gt; iterator);\n    ++iterator;\n}\n\nforeach (var act in actions)\n{\n    Console.WriteLine(act.Invoke());\n}\n<\/pre><\/div>\n\n\n<p>I know that is an old and tricky &#8216;feature&#8217; from Microsoft but it often raises during to job interview so I decided to remind everyone who has not heard about it before. <\/p>\n\n\n\n<p>Solution for this riddle you can find at Microsoft blog:<br><a href=\"https:\/\/blogs.msdn.microsoft.com\/abhinaba\/2005\/10\/18\/c-anonymous-methods-are-not-closures\/\">https:\/\/blogs.msdn.microsoft.com\/abhinaba\/2005\/10\/18\/c-anonymous-methods-are-not-closures\/<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It is the turn of programming riddle number 2. Now, it is dedicated to developers who coding in C#. So, the question is &#8211; what is the output of the following code: I know that is an old and tricky &#8216;feature&#8217; from Microsoft but it often raises during to job interview so I decided to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":359,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,16],"tags":[],"_links":{"self":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/430"}],"collection":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/comments?post=430"}],"version-history":[{"count":5,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/430\/revisions"}],"predecessor-version":[{"id":439,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/posts\/430\/revisions\/439"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/media\/359"}],"wp:attachment":[{"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/media?parent=430"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/categories?post=430"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paradysz.pl\/index.php\/wp-json\/wp\/v2\/tags?post=430"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}