{"id":118,"date":"2010-01-06T09:40:55","date_gmt":"2010-01-06T07:40:55","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=118"},"modified":"2010-01-06T09:40:55","modified_gmt":"2010-01-06T07:40:55","slug":"findall-convertall-are-your-friends","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/findall-convertall-are-your-friends","title":{"rendered":"FindAll, ConvertAll are your friends"},"content":{"rendered":"<p>Let&#8217;s take a look at following code:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic List&lt;string&gt; GetDeleteWarnings_ForEach()\n{\n    List&lt;string&gt; messages = new List&lt;string&gt;();\n    foreach (ItemReference reference in _itemReferences)\n    {\n        if (!reference.CanBeDeleted)\n        {\n            messages.Add(reference.DeleteMessage);\n        }\n    }\n    return messages;\n}\n<\/pre>\n<p>Using <em>FindAll <\/em>and <em>ConvertAll<\/em> you can do it in one, very obvious, line:<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic List&lt;string&gt; GetDeleteWarnings_Fluently()\n{\n    return _itemReferences\n        .FindAll(x =&gt; !x.CanBeDeleted)\n        .ConvertAll(x =&gt; x.DeleteMessage);\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s take a look at following code: public List&lt;string&gt; GetDeleteWarnings_ForEach() { List&lt;string&gt; messages = new List&lt;string&gt;(); foreach (ItemReference reference in _itemReferences) { if (!reference.CanBeDeleted) { messages.Add(reference.DeleteMessage); } } return messages; } Using FindAll and ConvertAll you can do it in one, very obvious, line: public List&lt;string&gt; GetDeleteWarnings_Fluently() { return _itemReferences .FindAll(x =&gt; !x.CanBeDeleted) .ConvertAll(x =&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[15],"class_list":["post-118","post","type-post","status-publish","format-standard","hentry","category-programming","tag-c"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/118"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=118"}],"version-history":[{"count":0,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/118\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=118"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=118"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=118"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}