{"id":14,"date":"2008-03-11T00:30:35","date_gmt":"2008-03-11T00:30:35","guid":{"rendered":"http:\/\/jcrawfor74.wordpress.com\/?p=14"},"modified":"2013-12-23T10:04:41","modified_gmt":"2013-12-22T23:04:41","slug":"listobject-find-with-delegate","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2008\/03\/11\/listobject-find-with-delegate\/","title":{"rendered":"List&lt;object&gt; Find with delegate"},"content":{"rendered":"<div id=\"ntsbl-3600406755\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><p>Thought this was really cool.<\/p>\n<p>I have a generic List of objects, for example:<\/p>\n<p>[csharp]List&lt;User&gt; users = GetAllUsers();[\/csharp]<\/p>\n<p>I want to find a user by username. Usually you would loop through looking for the item with the matching username and return the user that was found.<\/p>\n<p>or you could do this:<\/p>\n<p>[csharp]User loggedOnUser = users.Find(delegate(User u) { return u.Username == &quot;jbloggs&quot;; });[\/csharp]<\/p>\n<p>Much less code, and you could match on any property of the object that you wanted.<\/p>\n<p>Cheers<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Thought this was really cool. I have a generic List of objects, for example: [csharp]List&lt;User&gt; users = GetAllUsers();[\/csharp] I want to find a user by [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-c","category-code"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}