{"id":101,"date":"2017-08-01T17:24:00","date_gmt":"2017-08-01T17:24:00","guid":{"rendered":"https:\/\/jmrowe.com\/blog\/?p=101"},"modified":"2017-12-14T15:41:13","modified_gmt":"2017-12-14T15:41:13","slug":"c-ienumerable-notes","status":"publish","type":"post","link":"https:\/\/jmrowe.com\/blog\/c-ienumerable-notes\/","title":{"rendered":"C# IEnumerable notes"},"content":{"rendered":"<p><a href=\"https:\/\/jmrowe.com\/blog\/uncategorized\/c-ienumerable-notes\/attachment\/csharpienumerableexamples\" rel=\"attachment wp-att-102\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-102\" src=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2017\/08\/csharpIenumerableexamples-300x244.png\" alt=\"\" width=\"300\" height=\"244\" srcset=\"https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2017\/08\/csharpIenumerableexamples-300x244.png 300w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2017\/08\/csharpIenumerableexamples-624x508.png 624w, https:\/\/jmrowe.com\/blog\/wp-content\/uploads\/2017\/08\/csharpIenumerableexamples.png 637w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Examples of methods that must be implemented for the IEnumerable interface.<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Example of a class that has a collection of another object class that it wants to make available to foreach ( IEnumerbable )\"> class AnimalFarm : IEnumerable\r\n    {\r\n        private List&lt;Animal&gt; animalList = new List&lt;Animal&gt;();\r\n        public AnimalFarm(List&lt;Animal&gt; animalList)\r\n        {\r\n            this.animalList = animalList;\r\n        }\r\n\r\n        public AnimalFarm() { }\r\n\r\n        public Animal this[int index]\r\n        {\r\n            get { return (Animal)animalList[index]; }\r\n            set { animalList.Insert(index, value); }\r\n        }\r\n        public int Count { get { return animalList.Count; } }\r\n\r\n        IEnumerator IEnumerable.GetEnumerator()\r\n        {\r\n            return animalList.GetEnumerator();\r\n        }\r\n    }<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Examples of methods that must be implemented for the IEnumerable interface. class AnimalFarm : IEnumerable { private List&lt;Animal&gt; animalList = new List&lt;Animal&gt;(); public AnimalFarm(List&lt;Animal&gt; animalList) { this.animalList = animalList; } public AnimalFarm() { } public Animal this[int index] { get { return (Animal)animalList[index]; } set { animalList.Insert(index, value); } } public int Count { get [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-101","post","type-post","status-publish","format-standard","hentry","category-c"],"_links":{"self":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/101","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/comments?post=101"}],"version-history":[{"count":2,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions"}],"predecessor-version":[{"id":104,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/posts\/101\/revisions\/104"}],"wp:attachment":[{"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/media?parent=101"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/categories?post=101"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jmrowe.com\/blog\/wp-json\/wp\/v2\/tags?post=101"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}