{"id":15,"date":"2009-04-17T16:41:23","date_gmt":"2009-04-17T16:41:23","guid":{"rendered":"\/blogs\/benbarefield\/archive\/2009\/04\/17\/when-to-use-linq-for-foreach.aspx"},"modified":"2009-04-17T16:41:23","modified_gmt":"2009-04-17T16:41:23","slug":"when-to-use-linq-for-foreach","status":"publish","type":"post","link":"https:\/\/www.benbarefield.com\/blog\/2009\/04\/17\/when-to-use-linq-for-foreach\/","title":{"rendered":"When to use Linq: for\/foreach"},"content":{"rendered":"<p>Many people around the office love Linq, but I haven&#8217;t used it much and hadn&#8217;t heard about it until I started here. I have written a few Linq queries (Linq to Objects) but don&#8217;t use them extensively in my coding. In the last couple of days I have asked a few people what it is that causes them to go: &#8220;Oh! I should use Linq here.&#8221;&nbsp; I got replies like:<\/p>\n<p>&#8220;I always use Linq.&#8221;<br \/>&#8220;All the time.&#8221;<\/p>\n<p>After pushing a bit harder, someone said that Linq replaces for\/foreach loops pretty well. Last night I came up with a pretty nice Linq statement after realizing that I was going to write a foreach loop. Now when I go to write &#8220;for&#8221; I stop and think if Linq would work better.<\/p>\n<p>What key words trigger the &#8220;I should use Linq here&#8221; reaction in you?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Many people around the office love Linq, but I haven&#8217;t used it much and hadn&#8217;t heard about it until I started here. I have written a few Linq queries (Linq to Objects) but don&#8217;t use them extensively in my coding. &hellip; <a href=\"https:\/\/www.benbarefield.com\/blog\/2009\/04\/17\/when-to-use-linq-for-foreach\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,12],"tags":[],"class_list":["post-15","post","type-post","status-publish","format-standard","hentry","category-c","category-linq"],"_links":{"self":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/15","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/comments?post=15"}],"version-history":[{"count":0,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/posts\/15\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/media?parent=15"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/categories?post=15"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.benbarefield.com\/blog\/wp-json\/wp\/v2\/tags?post=15"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}