{"id":369,"date":"2016-08-23T12:39:45","date_gmt":"2016-08-23T16:39:45","guid":{"rendered":"http:\/\/salzlechner.com\/dev\/?p=369"},"modified":"2016-09-04T08:32:54","modified_gmt":"2016-09-04T12:32:54","slug":"using-linq-to-find-items-in-a-list","status":"publish","type":"post","link":"http:\/\/salzlechner.com\/dev\/2016\/08\/23\/using-linq-to-find-items-in-a-list\/","title":{"rendered":"Using Linq to find items in a List"},"content":{"rendered":"<p>With the following data<\/p>\n<pre class=\"lang:default decode:true \">public class Patient \r\n{\r\n    public string Name { get; set; }\r\n    public string Id { get; set; }\r\n}<\/pre>\n<p>and a list as follows<\/p>\n<pre class=\"lang:default decode:true \">public List&lt;Patient&gt; myPatients;\r\n<\/pre>\n<p>we can find items with Linq<\/p>\n<pre class=\"lang:default decode:true \">\/\/ find all patients that have a specific name\r\nvar patientsFound = patients.Where(p =&gt; p.Name.Equals(nameToFind));\r\n\r\n\/\/ find the first or default patient that has a specific name\r\nvar patientFound = patients.Where(p =&gt; p.Name.Equals(nameToFind)).FirstOrDefault();\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Simple example to use Linq for finding items in a list<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","ngg_post_thumbnail":0,"footnotes":""},"categories":[7,35],"tags":[],"class_list":["post-369","post","type-post","status-publish","format-standard","hentry","category-c","category-linq"],"_links":{"self":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/369","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":2,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":371,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/posts\/369\/revisions\/371"}],"wp:attachment":[{"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/salzlechner.com\/dev\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}