[{"data":1,"prerenderedAt":1660},["ShallowReactive",2],{"blog:2008:using-linq-to-foreach-over-an-enum-in-c":3,"blogMore-Development":497,"comments-using-linq-to-foreach-over-an-enum-in-c":510},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"category":11,"tags":12,"excerpt":16,"body":36,"_type":489,"_id":490,"_source":491,"_file":492,"_stem":493,"_extension":494,"url":495,"wordCount":496,"minutes":77,"commentCount":460},"/blog/2008/using-linq-to-foreach-over-an-enum-in-c","2008",false,"en","Using LINQ to foreach over an enum in C#","","2008-04-10T15:35:15+00:00","Development",[13,14,15],".NET","C#","LINQ",{"type":17,"children":18},"root",[19,31],{"type":20,"tag":21,"props":22,"children":23},"element","p",{},[24,27,29],{"type":25,"value":26},"text","I later expanded this out into ",{"type":25,"value":28},"a full Enum\u003CT> strongly typed helper",{"type":25,"value":30},".",{"type":20,"tag":21,"props":32,"children":33},{},[34],{"type":25,"value":35},"I can’t be the only person in the world who wants to foreach over the values of an enum otherwise Enum.GetValues(Type enumType) wouldn’t exist in the framework. Unfortunately it didn’t get any generics love in .NET 2.0 and unhelpfully returns an array.",{"type":17,"children":37,"toc":487},[38,53,57,62,161,166,219,224,467,472,481],{"type":20,"tag":39,"props":40,"children":41},"blockquote",{},[42],{"type":20,"tag":21,"props":43,"children":44},{},[45,46,52],{"type":25,"value":26},{"type":20,"tag":47,"props":48,"children":50},"a",{"href":49},"/blog/2010/enums-better-syntax-improved-performance-and-tryparse-in-net-3-5/",[51],{"type":25,"value":28},{"type":25,"value":30},{"type":20,"tag":21,"props":54,"children":55},{},[56],{"type":25,"value":35},{"type":20,"tag":21,"props":58,"children":59},{},[60],{"type":25,"value":61},"Thanks to the power of LINQ you can do this:",{"type":20,"tag":63,"props":64,"children":68},"pre",{"className":65,"code":66,"language":67,"meta":9,"style":9},"language-csharp shiki shiki-themes everforest-light dracula","foreach(var customerType in Enum.GetValues(typeof(CustomerTypes)).Cast\u003CCustomerTypes>()))\n","csharp",[69],{"type":20,"tag":70,"props":71,"children":72},"code",{"__ignoreMap":9},[73],{"type":20,"tag":74,"props":75,"children":78},"span",{"class":76,"line":77},"line",1,[79,85,91,97,102,107,112,118,122,127,131,137,142,147,152,156],{"type":20,"tag":74,"props":80,"children":82},{"style":81},"--shiki-default:#F85552;--shiki-dark:#FF79C6",[83],{"type":25,"value":84},"foreach",{"type":20,"tag":74,"props":86,"children":88},{"style":87},"--shiki-default:#5C6A72;--shiki-dark:#F8F8F2",[89],{"type":25,"value":90},"(",{"type":20,"tag":74,"props":92,"children":94},{"style":93},"--shiki-default:#3A94C5;--shiki-dark:#FF79C6",[95],{"type":25,"value":96},"var",{"type":20,"tag":74,"props":98,"children":99},{"style":87},[100],{"type":25,"value":101}," customerType ",{"type":20,"tag":74,"props":103,"children":104},{"style":81},[105],{"type":25,"value":106},"in",{"type":20,"tag":74,"props":108,"children":109},{"style":87},[110],{"type":25,"value":111}," Enum.",{"type":20,"tag":74,"props":113,"children":115},{"style":114},"--shiki-default:#8DA101;--shiki-dark:#50FA7B",[116],{"type":25,"value":117},"GetValues",{"type":20,"tag":74,"props":119,"children":120},{"style":87},[121],{"type":25,"value":90},{"type":20,"tag":74,"props":123,"children":124},{"style":81},[125],{"type":25,"value":126},"typeof",{"type":20,"tag":74,"props":128,"children":129},{"style":87},[130],{"type":25,"value":90},{"type":20,"tag":74,"props":132,"children":134},{"style":133},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[135],{"type":25,"value":136},"CustomerTypes",{"type":20,"tag":74,"props":138,"children":139},{"style":87},[140],{"type":25,"value":141},")).",{"type":20,"tag":74,"props":143,"children":144},{"style":114},[145],{"type":25,"value":146},"Cast",{"type":20,"tag":74,"props":148,"children":149},{"style":87},[150],{"type":25,"value":151},"\u003C",{"type":20,"tag":74,"props":153,"children":154},{"style":133},[155],{"type":25,"value":136},{"type":20,"tag":74,"props":157,"children":158},{"style":87},[159],{"type":25,"value":160},">()))\n",{"type":20,"tag":21,"props":162,"children":163},{},[164],{"type":25,"value":165},"That is okay, but this is more concise:",{"type":20,"tag":63,"props":167,"children":169},{"className":65,"code":168,"language":67,"meta":9,"style":9},"foreach(CustomerTypes customerType in Enums.Get\u003CCustomerTypes>())\n",[170],{"type":20,"tag":70,"props":171,"children":172},{"__ignoreMap":9},[173],{"type":20,"tag":74,"props":174,"children":175},{"class":76,"line":77},[176,180,184,188,192,196,201,206,210,214],{"type":20,"tag":74,"props":177,"children":178},{"style":81},[179],{"type":25,"value":84},{"type":20,"tag":74,"props":181,"children":182},{"style":87},[183],{"type":25,"value":90},{"type":20,"tag":74,"props":185,"children":186},{"style":133},[187],{"type":25,"value":136},{"type":20,"tag":74,"props":189,"children":190},{"style":87},[191],{"type":25,"value":101},{"type":20,"tag":74,"props":193,"children":194},{"style":81},[195],{"type":25,"value":106},{"type":20,"tag":74,"props":197,"children":198},{"style":87},[199],{"type":25,"value":200}," Enums.",{"type":20,"tag":74,"props":202,"children":203},{"style":114},[204],{"type":25,"value":205},"Get",{"type":20,"tag":74,"props":207,"children":208},{"style":87},[209],{"type":25,"value":151},{"type":20,"tag":74,"props":211,"children":212},{"style":133},[213],{"type":25,"value":136},{"type":20,"tag":74,"props":215,"children":216},{"style":87},[217],{"type":25,"value":218},">())\n",{"type":20,"tag":21,"props":220,"children":221},{},[222],{"type":25,"value":223},"The tiny class to achieve that is, of course:",{"type":20,"tag":63,"props":225,"children":227},{"className":65,"code":226,"language":67,"meta":9,"style":9},"using System.Collections.Generic;\nusing System.Linq;\n\npublic static class Enums {\n  public static IEnumerable\u003CT> Get\u003CT>() {\n    return System.Enum.GetValues(typeof(T)).Cast\u003CT>();\n  }\n}\n",[228],{"type":20,"tag":70,"props":229,"children":230},{"__ignoreMap":9},[231,268,293,303,334,384,449,458],{"type":20,"tag":74,"props":232,"children":233},{"class":76,"line":77},[234,239,245,249,254,258,263],{"type":20,"tag":74,"props":235,"children":236},{"style":81},[237],{"type":25,"value":238},"using",{"type":20,"tag":74,"props":240,"children":242},{"style":241},"--shiki-default:#DF69BA;--shiki-default-font-style:inherit;--shiki-dark:#8BE9FD;--shiki-dark-font-style:italic",[243],{"type":25,"value":244}," System",{"type":20,"tag":74,"props":246,"children":247},{"style":87},[248],{"type":25,"value":30},{"type":20,"tag":74,"props":250,"children":251},{"style":241},[252],{"type":25,"value":253},"Collections",{"type":20,"tag":74,"props":255,"children":256},{"style":87},[257],{"type":25,"value":30},{"type":20,"tag":74,"props":259,"children":260},{"style":241},[261],{"type":25,"value":262},"Generic",{"type":20,"tag":74,"props":264,"children":265},{"style":87},[266],{"type":25,"value":267},";\n",{"type":20,"tag":74,"props":269,"children":271},{"class":76,"line":270},2,[272,276,280,284,289],{"type":20,"tag":74,"props":273,"children":274},{"style":81},[275],{"type":25,"value":238},{"type":20,"tag":74,"props":277,"children":278},{"style":241},[279],{"type":25,"value":244},{"type":20,"tag":74,"props":281,"children":282},{"style":87},[283],{"type":25,"value":30},{"type":20,"tag":74,"props":285,"children":286},{"style":241},[287],{"type":25,"value":288},"Linq",{"type":20,"tag":74,"props":290,"children":291},{"style":87},[292],{"type":25,"value":267},{"type":20,"tag":74,"props":294,"children":296},{"class":76,"line":295},3,[297],{"type":20,"tag":74,"props":298,"children":300},{"emptyLinePlaceholder":299},true,[301],{"type":25,"value":302},"\n",{"type":20,"tag":74,"props":304,"children":306},{"class":76,"line":305},4,[307,313,318,323,329],{"type":20,"tag":74,"props":308,"children":310},{"style":309},"--shiki-default:#F57D26;--shiki-dark:#FF79C6",[311],{"type":25,"value":312},"public",{"type":20,"tag":74,"props":314,"children":315},{"style":309},[316],{"type":25,"value":317}," static",{"type":20,"tag":74,"props":319,"children":320},{"style":81},[321],{"type":25,"value":322}," class",{"type":20,"tag":74,"props":324,"children":326},{"style":325},"--shiki-default:#3A94C5;--shiki-dark:#8BE9FD",[327],{"type":25,"value":328}," Enums",{"type":20,"tag":74,"props":330,"children":331},{"style":87},[332],{"type":25,"value":333}," {\n",{"type":20,"tag":74,"props":335,"children":337},{"class":76,"line":336},5,[338,343,347,352,356,361,366,370,374,379],{"type":20,"tag":74,"props":339,"children":340},{"style":309},[341],{"type":25,"value":342},"  public",{"type":20,"tag":74,"props":344,"children":345},{"style":309},[346],{"type":25,"value":317},{"type":20,"tag":74,"props":348,"children":349},{"style":133},[350],{"type":25,"value":351}," IEnumerable",{"type":20,"tag":74,"props":353,"children":354},{"style":87},[355],{"type":25,"value":151},{"type":20,"tag":74,"props":357,"children":358},{"style":133},[359],{"type":25,"value":360},"T",{"type":20,"tag":74,"props":362,"children":363},{"style":87},[364],{"type":25,"value":365},"> ",{"type":20,"tag":74,"props":367,"children":368},{"style":114},[369],{"type":25,"value":205},{"type":20,"tag":74,"props":371,"children":372},{"style":87},[373],{"type":25,"value":151},{"type":20,"tag":74,"props":375,"children":377},{"style":376},"--shiki-default:#3A94C5;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[378],{"type":25,"value":360},{"type":20,"tag":74,"props":380,"children":381},{"style":87},[382],{"type":25,"value":383},">() {\n",{"type":20,"tag":74,"props":385,"children":387},{"class":76,"line":386},6,[388,393,398,404,408,412,416,420,424,428,432,436,440,444],{"type":20,"tag":74,"props":389,"children":390},{"style":81},[391],{"type":25,"value":392},"    return",{"type":20,"tag":74,"props":394,"children":395},{"style":87},[396],{"type":25,"value":397}," System.",{"type":20,"tag":74,"props":399,"children":401},{"style":400},"--shiki-default:#35A77C;--shiki-dark:#F8F8F2",[402],{"type":25,"value":403},"Enum",{"type":20,"tag":74,"props":405,"children":406},{"style":87},[407],{"type":25,"value":30},{"type":20,"tag":74,"props":409,"children":410},{"style":114},[411],{"type":25,"value":117},{"type":20,"tag":74,"props":413,"children":414},{"style":87},[415],{"type":25,"value":90},{"type":20,"tag":74,"props":417,"children":418},{"style":81},[419],{"type":25,"value":126},{"type":20,"tag":74,"props":421,"children":422},{"style":87},[423],{"type":25,"value":90},{"type":20,"tag":74,"props":425,"children":426},{"style":133},[427],{"type":25,"value":360},{"type":20,"tag":74,"props":429,"children":430},{"style":87},[431],{"type":25,"value":141},{"type":20,"tag":74,"props":433,"children":434},{"style":114},[435],{"type":25,"value":146},{"type":20,"tag":74,"props":437,"children":438},{"style":87},[439],{"type":25,"value":151},{"type":20,"tag":74,"props":441,"children":442},{"style":133},[443],{"type":25,"value":360},{"type":20,"tag":74,"props":445,"children":446},{"style":87},[447],{"type":25,"value":448},">();\n",{"type":20,"tag":74,"props":450,"children":452},{"class":76,"line":451},7,[453],{"type":20,"tag":74,"props":454,"children":455},{"style":87},[456],{"type":25,"value":457},"  }\n",{"type":20,"tag":74,"props":459,"children":461},{"class":76,"line":460},8,[462],{"type":20,"tag":74,"props":463,"children":464},{"style":87},[465],{"type":25,"value":466},"}\n",{"type":20,"tag":21,"props":468,"children":469},{},[470],{"type":25,"value":471},"Great.",{"type":20,"tag":21,"props":473,"children":474},{},[475],{"type":20,"tag":476,"props":477,"children":478},"em",{},[479],{"type":25,"value":480},"[)amien",{"type":20,"tag":482,"props":483,"children":484},"style",{},[485],{"type":25,"value":486},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":9,"searchDepth":270,"depth":270,"links":488},[],"markdown","content:blog:2008:using-linq-to-foreach-over-an-enum-in-c.md","content","blog/2008/using-linq-to-foreach-over-an-enum-in-c.md","blog/2008/using-linq-to-foreach-over-an-enum-in-c","md","/blog/2008/using-linq-to-foreach-over-an-enum-in-c/",190,[498,502,506],{"title":499,"date":500,"url":501},"HTML5 Video Cheatsheet: Optimizing videos for the web","2025-12-05T00:00:00Z","/blog/2025/html5-video-cheatsheet/",{"title":503,"date":504,"url":505},"Transactions in the MongoDB EF Core Provider","2025-10-25","/blog/2025/mongodb-explicit-transactions/",{"title":507,"date":508,"url":509},"Queryable Encryption with the MongoDB EF Core Provider","2025-09-22","/blog/2025/mongodb-queryable-encryption/",[511,616,891,921,942,1523,1607,1634],{"_path":512,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":514,"description":515,"id":516,"name":517,"email":518,"avatar":519,"date":520,"body":521,"_type":489,"_id":613,"_source":491,"_file":614,"_stem":615,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/42631","using-linq-to-foreach-over-an-enum-in-c","42631","Thanks for the post. I was able to use it along with another posting regarding custom attributes\n to list out friendly names for enums in a dropdown, in a view in an MVC project (with a nice bit of LINQ).",42631,"Jesse Pakin","jpakin@gmail.com","https://www.gravatar.com/avatar/a0a9186783e24c53959f2d8779f4a3dc?r=pg&d=retro","2010-11-08T20:43:42",{"type":17,"children":522,"toc":611},[523,536,607],{"type":20,"tag":21,"props":524,"children":525},{},[526,528,534],{"type":25,"value":527},"Thanks for the post. I was able to use it along with ",{"type":20,"tag":47,"props":529,"children":531},{"href":530},"https://weblogs.asp.net/stefansedich/archive/2008/03/12/enum-with-string-values-in-c.aspx",[532],{"type":25,"value":533},"another posting regarding custom attributes\n",{"type":25,"value":535}," to list out friendly names for enums in a dropdown, in a view in an MVC project (with a nice bit of LINQ).",{"type":20,"tag":63,"props":537,"children":541},{"className":538,"code":539,"language":540,"meta":9,"style":9},"language-html shiki shiki-themes everforest-light dracula","\u003C%: Html.DropDownList(\"CardRecord.Type\",((IList\u003CCreditCardType\n  >)Enum.GetValues(typeof(CreditCardType))).Select(s => new SelectListItem{Text\n  = s.GetStringValue(), Value = s.ToString()}))%>\u003C/CreditCardType\n>\n","html",[542],{"type":20,"tag":70,"props":543,"children":544},{"__ignoreMap":9},[545,569,582,599],{"type":20,"tag":74,"props":546,"children":547},{"class":76,"line":77},[548,553,558,563],{"type":20,"tag":74,"props":549,"children":551},{"style":550},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-default-text-decoration:inherit;--shiki-dark:#FF5555;--shiki-dark-font-style:italic;--shiki-dark-text-decoration:underline",[552],{"type":25,"value":151},{"type":20,"tag":74,"props":554,"children":555},{"style":87},[556],{"type":25,"value":557},"%: Html.DropDownList(\"CardRecord.Type\",((IList",{"type":20,"tag":74,"props":559,"children":561},{"style":560},"--shiki-default:#8DA101;--shiki-dark:#F8F8F2",[562],{"type":25,"value":151},{"type":20,"tag":74,"props":564,"children":566},{"style":565},"--shiki-default:#F57D26;--shiki-default-font-style:inherit;--shiki-default-text-decoration:inherit;--shiki-dark:#FF5555;--shiki-dark-font-style:italic;--shiki-dark-text-decoration:underline",[567],{"type":25,"value":568},"CreditCardType\n",{"type":20,"tag":74,"props":570,"children":571},{"class":76,"line":270},[572,577],{"type":20,"tag":74,"props":573,"children":574},{"style":560},[575],{"type":25,"value":576},"  >",{"type":20,"tag":74,"props":578,"children":579},{"style":87},[580],{"type":25,"value":581},")Enum.GetValues(typeof(CreditCardType))).Select(s => new SelectListItem{Text\n",{"type":20,"tag":74,"props":583,"children":584},{"class":76,"line":295},[585,590,595],{"type":20,"tag":74,"props":586,"children":587},{"style":87},[588],{"type":25,"value":589},"  = s.GetStringValue(), Value = s.ToString()}))%>",{"type":20,"tag":74,"props":591,"children":592},{"style":560},[593],{"type":25,"value":594},"\u003C/",{"type":20,"tag":74,"props":596,"children":597},{"style":565},[598],{"type":25,"value":568},{"type":20,"tag":74,"props":600,"children":601},{"class":76,"line":305},[602],{"type":20,"tag":74,"props":603,"children":604},{"style":560},[605],{"type":25,"value":606},">\n",{"type":20,"tag":482,"props":608,"children":609},{},[610],{"type":25,"value":486},{"title":9,"searchDepth":270,"depth":270,"links":612},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:42631.md","comments/using-linq-to-foreach-over-an-enum-in-c/42631.md","comments/using-linq-to-foreach-over-an-enum-in-c/42631",{"_path":617,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":618,"description":619,"id":620,"name":621,"email":622,"avatar":623,"date":624,"body":625,"_type":489,"_id":888,"_source":491,"_file":889,"_stem":890,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8263","8263","Hi guys :)",8263,"Florent","bigflo@live.fr","https://www.gravatar.com/avatar/dfd03ffbc49ce98c350343f21159c216?r=pg&d=retro","2008-04-15T06:56:12",{"type":17,"children":626,"toc":886},[627,631,659,664,743,748,877,882],{"type":20,"tag":21,"props":628,"children":629},{},[630],{"type":25,"value":619},{"type":20,"tag":21,"props":632,"children":633},{},[634,636,641,643,649,651,657],{"type":25,"value":635},"I think that ",{"type":20,"tag":70,"props":637,"children":639},{"className":638},[],[640],{"type":25,"value":146},{"type":25,"value":642}," method is not mandatory... In fact, you can directly cast that ",{"type":20,"tag":70,"props":644,"children":646},{"className":645},[],[647],{"type":25,"value":648},"Enum.GetValues",{"type":25,"value":650}," return into ",{"type":20,"tag":70,"props":652,"children":654},{"className":653},[],[655],{"type":25,"value":656},"IEnumerable",{"type":25,"value":658},". Because it's a simple array :)",{"type":20,"tag":21,"props":660,"children":661},{},[662],{"type":25,"value":663},"So you can do like this:",{"type":20,"tag":63,"props":665,"children":667},{"className":65,"code":666,"language":67,"meta":9,"style":9},"IEnumerable\u003CT> myEnumerableOfEnum = (IEnumerable\u003CT>)Enum.GetValues(typeof(T));\n",[668],{"type":20,"tag":70,"props":669,"children":670},{"__ignoreMap":9},[671],{"type":20,"tag":74,"props":672,"children":673},{"class":76,"line":77},[674,678,682,686,691,696,701,705,709,713,718,722,726,730,734,738],{"type":20,"tag":74,"props":675,"children":676},{"style":133},[677],{"type":25,"value":656},{"type":20,"tag":74,"props":679,"children":680},{"style":87},[681],{"type":25,"value":151},{"type":20,"tag":74,"props":683,"children":684},{"style":133},[685],{"type":25,"value":360},{"type":20,"tag":74,"props":687,"children":688},{"style":87},[689],{"type":25,"value":690},"> myEnumerableOfEnum ",{"type":20,"tag":74,"props":692,"children":693},{"style":309},[694],{"type":25,"value":695},"=",{"type":20,"tag":74,"props":697,"children":698},{"style":87},[699],{"type":25,"value":700}," (",{"type":20,"tag":74,"props":702,"children":703},{"style":133},[704],{"type":25,"value":656},{"type":20,"tag":74,"props":706,"children":707},{"style":87},[708],{"type":25,"value":151},{"type":20,"tag":74,"props":710,"children":711},{"style":133},[712],{"type":25,"value":360},{"type":20,"tag":74,"props":714,"children":715},{"style":87},[716],{"type":25,"value":717},">)Enum.",{"type":20,"tag":74,"props":719,"children":720},{"style":114},[721],{"type":25,"value":117},{"type":20,"tag":74,"props":723,"children":724},{"style":87},[725],{"type":25,"value":90},{"type":20,"tag":74,"props":727,"children":728},{"style":81},[729],{"type":25,"value":126},{"type":20,"tag":74,"props":731,"children":732},{"style":87},[733],{"type":25,"value":90},{"type":20,"tag":74,"props":735,"children":736},{"style":133},[737],{"type":25,"value":360},{"type":20,"tag":74,"props":739,"children":740},{"style":87},[741],{"type":25,"value":742},"));\n",{"type":20,"tag":21,"props":744,"children":745},{},[746],{"type":25,"value":747},"But you can do this too:",{"type":20,"tag":63,"props":749,"children":751},{"className":65,"code":750,"language":67,"meta":9,"style":9},"IList\u003CT> myListOfEnum = (IList\u003CT>)Enum.GetValues(typeof(T));\nT[] myArrayOfEnum = (T[])Enum.GetValues(typeof(T));\n",[752],{"type":20,"tag":70,"props":753,"children":754},{"__ignoreMap":9},[755,824],{"type":20,"tag":74,"props":756,"children":757},{"class":76,"line":77},[758,763,767,771,776,780,784,788,792,796,800,804,808,812,816,820],{"type":20,"tag":74,"props":759,"children":760},{"style":133},[761],{"type":25,"value":762},"IList",{"type":20,"tag":74,"props":764,"children":765},{"style":87},[766],{"type":25,"value":151},{"type":20,"tag":74,"props":768,"children":769},{"style":133},[770],{"type":25,"value":360},{"type":20,"tag":74,"props":772,"children":773},{"style":87},[774],{"type":25,"value":775},"> myListOfEnum ",{"type":20,"tag":74,"props":777,"children":778},{"style":309},[779],{"type":25,"value":695},{"type":20,"tag":74,"props":781,"children":782},{"style":87},[783],{"type":25,"value":700},{"type":20,"tag":74,"props":785,"children":786},{"style":133},[787],{"type":25,"value":762},{"type":20,"tag":74,"props":789,"children":790},{"style":87},[791],{"type":25,"value":151},{"type":20,"tag":74,"props":793,"children":794},{"style":133},[795],{"type":25,"value":360},{"type":20,"tag":74,"props":797,"children":798},{"style":87},[799],{"type":25,"value":717},{"type":20,"tag":74,"props":801,"children":802},{"style":114},[803],{"type":25,"value":117},{"type":20,"tag":74,"props":805,"children":806},{"style":87},[807],{"type":25,"value":90},{"type":20,"tag":74,"props":809,"children":810},{"style":81},[811],{"type":25,"value":126},{"type":20,"tag":74,"props":813,"children":814},{"style":87},[815],{"type":25,"value":90},{"type":20,"tag":74,"props":817,"children":818},{"style":133},[819],{"type":25,"value":360},{"type":20,"tag":74,"props":821,"children":822},{"style":87},[823],{"type":25,"value":742},{"type":20,"tag":74,"props":825,"children":826},{"class":76,"line":270},[827,831,836,840,844,848,853,857,861,865,869,873],{"type":20,"tag":74,"props":828,"children":829},{"style":133},[830],{"type":25,"value":360},{"type":20,"tag":74,"props":832,"children":833},{"style":87},[834],{"type":25,"value":835},"[] myArrayOfEnum ",{"type":20,"tag":74,"props":837,"children":838},{"style":309},[839],{"type":25,"value":695},{"type":20,"tag":74,"props":841,"children":842},{"style":87},[843],{"type":25,"value":700},{"type":20,"tag":74,"props":845,"children":846},{"style":133},[847],{"type":25,"value":360},{"type":20,"tag":74,"props":849,"children":850},{"style":87},[851],{"type":25,"value":852},"[])Enum.",{"type":20,"tag":74,"props":854,"children":855},{"style":114},[856],{"type":25,"value":117},{"type":20,"tag":74,"props":858,"children":859},{"style":87},[860],{"type":25,"value":90},{"type":20,"tag":74,"props":862,"children":863},{"style":81},[864],{"type":25,"value":126},{"type":20,"tag":74,"props":866,"children":867},{"style":87},[868],{"type":25,"value":90},{"type":20,"tag":74,"props":870,"children":871},{"style":133},[872],{"type":25,"value":360},{"type":20,"tag":74,"props":874,"children":875},{"style":87},[876],{"type":25,"value":742},{"type":20,"tag":21,"props":878,"children":879},{},[880],{"type":25,"value":881},"I hope this will useful :)",{"type":20,"tag":482,"props":883,"children":884},{},[885],{"type":25,"value":486},{"title":9,"searchDepth":270,"depth":270,"links":887},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8263.md","comments/using-linq-to-foreach-over-an-enum-in-c/8263.md","comments/using-linq-to-foreach-over-an-enum-in-c/8263",{"_path":892,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":893,"description":9,"id":894,"name":895,"email":896,"avatar":897,"date":898,"body":899,"_type":489,"_id":918,"_source":491,"_file":919,"_stem":920,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8242","8242",8242,"Richard","richard@rjcox.co.uk","https://www.gravatar.com/avatar/95e28ac250c4604a6f9d7e34705c3259?r=pg&d=retro","2008-04-13T07:37:21",{"type":17,"children":900,"toc":916},[901,906,911],{"type":20,"tag":39,"props":902,"children":903},{},[904],{"type":25,"value":905},"hope you don't mind me reformatting it",{"type":20,"tag":21,"props":907,"children":908},{},[909],{"type":25,"value":910},"No problem.",{"type":20,"tag":21,"props":912,"children":913},{},[914],{"type":25,"value":915},"This is the second time I would have liked to write an extension method that extends the target's static methods (rather than instance).",{"title":9,"searchDepth":270,"depth":270,"links":917},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8242.md","comments/using-linq-to-foreach-over-an-enum-in-c/8242.md","comments/using-linq-to-foreach-over-an-enum-in-c/8242",{"_path":922,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":923,"description":924,"id":925,"name":926,"email":927,"avatar":928,"url":929,"date":930,"body":931,"_type":489,"_id":939,"_source":491,"_file":940,"_stem":941,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8239","8239","That's nice! (hope you don't mind me reformatting it).  I did consider going with an extension method but my worry was having .Values appear for all classes.",8239,"Damien Guard","damien@envytech.co.uk","https://www.gravatar.com/avatar/dc72963e7279d34c85ed4c0b731ce5a9?r=pg&d=retro","https://damieng.com/","2008-04-12T09:30:01",{"type":17,"children":932,"toc":937},[933],{"type":20,"tag":21,"props":934,"children":935},{},[936],{"type":25,"value":924},{"title":9,"searchDepth":270,"depth":270,"links":938},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8239.md","comments/using-linq-to-foreach-over-an-enum-in-c/8239.md","comments/using-linq-to-foreach-over-an-enum-in-c/8239",{"_path":943,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":944,"description":945,"id":946,"name":895,"email":896,"avatar":897,"date":947,"body":948,"_type":489,"_id":1520,"_source":491,"_file":1521,"_stem":1522,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8238","8238","You can make use of an extension method to make this slightly nicer... but you call the extension against an instance of the enum (naming for the extension needs to be better):",8238,"2008-04-12T07:56:01",{"type":17,"children":949,"toc":1518},[950,954,1514],{"type":20,"tag":21,"props":951,"children":952},{},[953],{"type":25,"value":945},{"type":20,"tag":63,"props":955,"children":957},{"className":65,"code":956,"language":67,"meta":9,"style":9},"using System;\nusing System.Collections.Generic;\nusing System.Linq;\n\nstatic class Enums {\n    public static IEnumerable\u003CT> Values\u003CT>(this T en) where T : struct {\n        if (!typeof(T).IsEnum)\n            throw new InvalidOperationException();\n        foreach (var x inEnum.GetValues(typeof(T)).Cast\u003CT>())\n            yield return x;\n    }\n}\n\nenum Test { One, Two, Three }\n\nclass Program {\n    static void Main(string[] args) {\n        IEnumerable\u003CTest> t = Test.One.Values();\n        foreach (var x in t)\n            Console.WriteLine(x);\n    }\n}\n",[958],{"type":20,"tag":70,"props":959,"children":960},{"__ignoreMap":9},[961,976,1007,1030,1037,1057,1147,1191,1214,1268,1287,1296,1304,1312,1331,1339,1357,1400,1449,1479,1498,1506],{"type":20,"tag":74,"props":962,"children":963},{"class":76,"line":77},[964,968,972],{"type":20,"tag":74,"props":965,"children":966},{"style":81},[967],{"type":25,"value":238},{"type":20,"tag":74,"props":969,"children":970},{"style":241},[971],{"type":25,"value":244},{"type":20,"tag":74,"props":973,"children":974},{"style":87},[975],{"type":25,"value":267},{"type":20,"tag":74,"props":977,"children":978},{"class":76,"line":270},[979,983,987,991,995,999,1003],{"type":20,"tag":74,"props":980,"children":981},{"style":81},[982],{"type":25,"value":238},{"type":20,"tag":74,"props":984,"children":985},{"style":241},[986],{"type":25,"value":244},{"type":20,"tag":74,"props":988,"children":989},{"style":87},[990],{"type":25,"value":30},{"type":20,"tag":74,"props":992,"children":993},{"style":241},[994],{"type":25,"value":253},{"type":20,"tag":74,"props":996,"children":997},{"style":87},[998],{"type":25,"value":30},{"type":20,"tag":74,"props":1000,"children":1001},{"style":241},[1002],{"type":25,"value":262},{"type":20,"tag":74,"props":1004,"children":1005},{"style":87},[1006],{"type":25,"value":267},{"type":20,"tag":74,"props":1008,"children":1009},{"class":76,"line":295},[1010,1014,1018,1022,1026],{"type":20,"tag":74,"props":1011,"children":1012},{"style":81},[1013],{"type":25,"value":238},{"type":20,"tag":74,"props":1015,"children":1016},{"style":241},[1017],{"type":25,"value":244},{"type":20,"tag":74,"props":1019,"children":1020},{"style":87},[1021],{"type":25,"value":30},{"type":20,"tag":74,"props":1023,"children":1024},{"style":241},[1025],{"type":25,"value":288},{"type":20,"tag":74,"props":1027,"children":1028},{"style":87},[1029],{"type":25,"value":267},{"type":20,"tag":74,"props":1031,"children":1032},{"class":76,"line":305},[1033],{"type":20,"tag":74,"props":1034,"children":1035},{"emptyLinePlaceholder":299},[1036],{"type":25,"value":302},{"type":20,"tag":74,"props":1038,"children":1039},{"class":76,"line":336},[1040,1045,1049,1053],{"type":20,"tag":74,"props":1041,"children":1042},{"style":309},[1043],{"type":25,"value":1044},"static",{"type":20,"tag":74,"props":1046,"children":1047},{"style":81},[1048],{"type":25,"value":322},{"type":20,"tag":74,"props":1050,"children":1051},{"style":325},[1052],{"type":25,"value":328},{"type":20,"tag":74,"props":1054,"children":1055},{"style":87},[1056],{"type":25,"value":333},{"type":20,"tag":74,"props":1058,"children":1059},{"class":76,"line":386},[1060,1065,1069,1073,1077,1081,1085,1090,1094,1098,1103,1108,1113,1119,1124,1129,1133,1138,1143],{"type":20,"tag":74,"props":1061,"children":1062},{"style":309},[1063],{"type":25,"value":1064},"    public",{"type":20,"tag":74,"props":1066,"children":1067},{"style":309},[1068],{"type":25,"value":317},{"type":20,"tag":74,"props":1070,"children":1071},{"style":133},[1072],{"type":25,"value":351},{"type":20,"tag":74,"props":1074,"children":1075},{"style":87},[1076],{"type":25,"value":151},{"type":20,"tag":74,"props":1078,"children":1079},{"style":133},[1080],{"type":25,"value":360},{"type":20,"tag":74,"props":1082,"children":1083},{"style":87},[1084],{"type":25,"value":365},{"type":20,"tag":74,"props":1086,"children":1087},{"style":114},[1088],{"type":25,"value":1089},"Values",{"type":20,"tag":74,"props":1091,"children":1092},{"style":87},[1093],{"type":25,"value":151},{"type":20,"tag":74,"props":1095,"children":1096},{"style":376},[1097],{"type":25,"value":360},{"type":20,"tag":74,"props":1099,"children":1100},{"style":87},[1101],{"type":25,"value":1102},">(",{"type":20,"tag":74,"props":1104,"children":1105},{"style":309},[1106],{"type":25,"value":1107},"this",{"type":20,"tag":74,"props":1109,"children":1110},{"style":133},[1111],{"type":25,"value":1112}," T",{"type":20,"tag":74,"props":1114,"children":1116},{"style":1115},"--shiki-default:#5C6A72;--shiki-default-font-style:inherit;--shiki-dark:#FFB86C;--shiki-dark-font-style:italic",[1117],{"type":25,"value":1118}," en",{"type":20,"tag":74,"props":1120,"children":1121},{"style":87},[1122],{"type":25,"value":1123},") ",{"type":20,"tag":74,"props":1125,"children":1126},{"style":309},[1127],{"type":25,"value":1128},"where",{"type":20,"tag":74,"props":1130,"children":1131},{"style":376},[1132],{"type":25,"value":1112},{"type":20,"tag":74,"props":1134,"children":1135},{"style":87},[1136],{"type":25,"value":1137}," : ",{"type":20,"tag":74,"props":1139,"children":1140},{"style":93},[1141],{"type":25,"value":1142},"struct",{"type":20,"tag":74,"props":1144,"children":1145},{"style":87},[1146],{"type":25,"value":333},{"type":20,"tag":74,"props":1148,"children":1149},{"class":76,"line":451},[1150,1155,1159,1164,1168,1172,1176,1181,1186],{"type":20,"tag":74,"props":1151,"children":1152},{"style":81},[1153],{"type":25,"value":1154},"        if",{"type":20,"tag":74,"props":1156,"children":1157},{"style":87},[1158],{"type":25,"value":700},{"type":20,"tag":74,"props":1160,"children":1161},{"style":309},[1162],{"type":25,"value":1163},"!",{"type":20,"tag":74,"props":1165,"children":1166},{"style":81},[1167],{"type":25,"value":126},{"type":20,"tag":74,"props":1169,"children":1170},{"style":87},[1171],{"type":25,"value":90},{"type":20,"tag":74,"props":1173,"children":1174},{"style":133},[1175],{"type":25,"value":360},{"type":20,"tag":74,"props":1177,"children":1178},{"style":87},[1179],{"type":25,"value":1180},").",{"type":20,"tag":74,"props":1182,"children":1183},{"style":400},[1184],{"type":25,"value":1185},"IsEnum",{"type":20,"tag":74,"props":1187,"children":1188},{"style":87},[1189],{"type":25,"value":1190},")\n",{"type":20,"tag":74,"props":1192,"children":1193},{"class":76,"line":460},[1194,1199,1204,1209],{"type":20,"tag":74,"props":1195,"children":1196},{"style":81},[1197],{"type":25,"value":1198},"            throw",{"type":20,"tag":74,"props":1200,"children":1201},{"style":81},[1202],{"type":25,"value":1203}," new",{"type":20,"tag":74,"props":1205,"children":1206},{"style":133},[1207],{"type":25,"value":1208}," InvalidOperationException",{"type":20,"tag":74,"props":1210,"children":1211},{"style":87},[1212],{"type":25,"value":1213},"();\n",{"type":20,"tag":74,"props":1215,"children":1217},{"class":76,"line":1216},9,[1218,1223,1228,1232,1236,1240,1244,1248,1252,1256,1260,1264],{"type":20,"tag":74,"props":1219,"children":1220},{"style":81},[1221],{"type":25,"value":1222},"        foreach",{"type":20,"tag":74,"props":1224,"children":1225},{"style":87},[1226],{"type":25,"value":1227}," (var x inEnum.",{"type":20,"tag":74,"props":1229,"children":1230},{"style":114},[1231],{"type":25,"value":117},{"type":20,"tag":74,"props":1233,"children":1234},{"style":87},[1235],{"type":25,"value":90},{"type":20,"tag":74,"props":1237,"children":1238},{"style":81},[1239],{"type":25,"value":126},{"type":20,"tag":74,"props":1241,"children":1242},{"style":87},[1243],{"type":25,"value":90},{"type":20,"tag":74,"props":1245,"children":1246},{"style":133},[1247],{"type":25,"value":360},{"type":20,"tag":74,"props":1249,"children":1250},{"style":87},[1251],{"type":25,"value":141},{"type":20,"tag":74,"props":1253,"children":1254},{"style":114},[1255],{"type":25,"value":146},{"type":20,"tag":74,"props":1257,"children":1258},{"style":87},[1259],{"type":25,"value":151},{"type":20,"tag":74,"props":1261,"children":1262},{"style":133},[1263],{"type":25,"value":360},{"type":20,"tag":74,"props":1265,"children":1266},{"style":87},[1267],{"type":25,"value":218},{"type":20,"tag":74,"props":1269,"children":1271},{"class":76,"line":1270},10,[1272,1277,1282],{"type":20,"tag":74,"props":1273,"children":1274},{"style":81},[1275],{"type":25,"value":1276},"            yield",{"type":20,"tag":74,"props":1278,"children":1279},{"style":81},[1280],{"type":25,"value":1281}," return",{"type":20,"tag":74,"props":1283,"children":1284},{"style":87},[1285],{"type":25,"value":1286}," x;\n",{"type":20,"tag":74,"props":1288,"children":1290},{"class":76,"line":1289},11,[1291],{"type":20,"tag":74,"props":1292,"children":1293},{"style":87},[1294],{"type":25,"value":1295},"    }\n",{"type":20,"tag":74,"props":1297,"children":1299},{"class":76,"line":1298},12,[1300],{"type":20,"tag":74,"props":1301,"children":1302},{"style":87},[1303],{"type":25,"value":466},{"type":20,"tag":74,"props":1305,"children":1307},{"class":76,"line":1306},13,[1308],{"type":20,"tag":74,"props":1309,"children":1310},{"emptyLinePlaceholder":299},[1311],{"type":25,"value":302},{"type":20,"tag":74,"props":1313,"children":1315},{"class":76,"line":1314},14,[1316,1321,1326],{"type":20,"tag":74,"props":1317,"children":1318},{"style":81},[1319],{"type":25,"value":1320},"enum",{"type":20,"tag":74,"props":1322,"children":1323},{"style":133},[1324],{"type":25,"value":1325}," Test",{"type":20,"tag":74,"props":1327,"children":1328},{"style":87},[1329],{"type":25,"value":1330}," { One, Two, Three }\n",{"type":20,"tag":74,"props":1332,"children":1334},{"class":76,"line":1333},15,[1335],{"type":20,"tag":74,"props":1336,"children":1337},{"emptyLinePlaceholder":299},[1338],{"type":25,"value":302},{"type":20,"tag":74,"props":1340,"children":1342},{"class":76,"line":1341},16,[1343,1348,1353],{"type":20,"tag":74,"props":1344,"children":1345},{"style":81},[1346],{"type":25,"value":1347},"class",{"type":20,"tag":74,"props":1349,"children":1350},{"style":325},[1351],{"type":25,"value":1352}," Program",{"type":20,"tag":74,"props":1354,"children":1355},{"style":87},[1356],{"type":25,"value":333},{"type":20,"tag":74,"props":1358,"children":1360},{"class":76,"line":1359},17,[1361,1366,1371,1376,1380,1385,1390,1395],{"type":20,"tag":74,"props":1362,"children":1363},{"style":309},[1364],{"type":25,"value":1365},"    static",{"type":20,"tag":74,"props":1367,"children":1368},{"style":93},[1369],{"type":25,"value":1370}," void",{"type":20,"tag":74,"props":1372,"children":1373},{"style":114},[1374],{"type":25,"value":1375}," Main",{"type":20,"tag":74,"props":1377,"children":1378},{"style":87},[1379],{"type":25,"value":90},{"type":20,"tag":74,"props":1381,"children":1382},{"style":93},[1383],{"type":25,"value":1384},"string",{"type":20,"tag":74,"props":1386,"children":1387},{"style":87},[1388],{"type":25,"value":1389},"[] ",{"type":20,"tag":74,"props":1391,"children":1392},{"style":1115},[1393],{"type":25,"value":1394},"args",{"type":20,"tag":74,"props":1396,"children":1397},{"style":87},[1398],{"type":25,"value":1399},") {\n",{"type":20,"tag":74,"props":1401,"children":1403},{"class":76,"line":1402},18,[1404,1409,1413,1418,1423,1427,1432,1437,1441,1445],{"type":20,"tag":74,"props":1405,"children":1406},{"style":133},[1407],{"type":25,"value":1408},"        IEnumerable",{"type":20,"tag":74,"props":1410,"children":1411},{"style":87},[1412],{"type":25,"value":151},{"type":20,"tag":74,"props":1414,"children":1415},{"style":133},[1416],{"type":25,"value":1417},"Test",{"type":20,"tag":74,"props":1419,"children":1420},{"style":87},[1421],{"type":25,"value":1422},"> t ",{"type":20,"tag":74,"props":1424,"children":1425},{"style":309},[1426],{"type":25,"value":695},{"type":20,"tag":74,"props":1428,"children":1429},{"style":87},[1430],{"type":25,"value":1431}," Test.",{"type":20,"tag":74,"props":1433,"children":1434},{"style":400},[1435],{"type":25,"value":1436},"One",{"type":20,"tag":74,"props":1438,"children":1439},{"style":87},[1440],{"type":25,"value":30},{"type":20,"tag":74,"props":1442,"children":1443},{"style":114},[1444],{"type":25,"value":1089},{"type":20,"tag":74,"props":1446,"children":1447},{"style":87},[1448],{"type":25,"value":1213},{"type":20,"tag":74,"props":1450,"children":1452},{"class":76,"line":1451},19,[1453,1457,1461,1465,1470,1474],{"type":20,"tag":74,"props":1454,"children":1455},{"style":81},[1456],{"type":25,"value":1222},{"type":20,"tag":74,"props":1458,"children":1459},{"style":87},[1460],{"type":25,"value":700},{"type":20,"tag":74,"props":1462,"children":1463},{"style":93},[1464],{"type":25,"value":96},{"type":20,"tag":74,"props":1466,"children":1467},{"style":87},[1468],{"type":25,"value":1469}," x ",{"type":20,"tag":74,"props":1471,"children":1472},{"style":81},[1473],{"type":25,"value":106},{"type":20,"tag":74,"props":1475,"children":1476},{"style":87},[1477],{"type":25,"value":1478}," t)\n",{"type":20,"tag":74,"props":1480,"children":1482},{"class":76,"line":1481},20,[1483,1488,1493],{"type":20,"tag":74,"props":1484,"children":1485},{"style":87},[1486],{"type":25,"value":1487},"            Console.",{"type":20,"tag":74,"props":1489,"children":1490},{"style":114},[1491],{"type":25,"value":1492},"WriteLine",{"type":20,"tag":74,"props":1494,"children":1495},{"style":87},[1496],{"type":25,"value":1497},"(x);\n",{"type":20,"tag":74,"props":1499,"children":1501},{"class":76,"line":1500},21,[1502],{"type":20,"tag":74,"props":1503,"children":1504},{"style":87},[1505],{"type":25,"value":1295},{"type":20,"tag":74,"props":1507,"children":1509},{"class":76,"line":1508},22,[1510],{"type":20,"tag":74,"props":1511,"children":1512},{"style":87},[1513],{"type":25,"value":466},{"type":20,"tag":482,"props":1515,"children":1516},{},[1517],{"type":25,"value":486},{"title":9,"searchDepth":270,"depth":270,"links":1519},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8238.md","comments/using-linq-to-foreach-over-an-enum-in-c/8238.md","comments/using-linq-to-foreach-over-an-enum-in-c/8238",{"_path":1524,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":1525,"description":1526,"id":1527,"name":1528,"email":1529,"avatar":1530,"url":1531,"date":1532,"body":1533,"_type":489,"_id":1604,"_source":491,"_file":1605,"_stem":1606,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8203","8203","Yuck. Equivalent Java code:",8203,"Steve","steves@stevestreeting.com","https://www.gravatar.com/avatar/970094b8699631d1de5832810b0aa837?r=pg&d=retro","https://www.stevestreeting.com","2008-04-10T21:25:13",{"type":17,"children":1534,"toc":1602},[1535,1539,1593,1598],{"type":20,"tag":21,"props":1536,"children":1537},{},[1538],{"type":25,"value":1526},{"type":20,"tag":63,"props":1540,"children":1544},{"className":1541,"code":1542,"language":1543,"meta":9,"style":9},"language-java shiki shiki-themes everforest-light dracula","for (CustomerTypes customerType : CustomerTypes.values())\n","java",[1545],{"type":20,"tag":70,"props":1546,"children":1547},{"__ignoreMap":9},[1548],{"type":20,"tag":74,"props":1549,"children":1550},{"class":76,"line":77},[1551,1556,1560,1564,1568,1573,1578,1583,1588],{"type":20,"tag":74,"props":1552,"children":1553},{"style":81},[1554],{"type":25,"value":1555},"for",{"type":20,"tag":74,"props":1557,"children":1558},{"style":87},[1559],{"type":25,"value":700},{"type":20,"tag":74,"props":1561,"children":1562},{"style":133},[1563],{"type":25,"value":136},{"type":20,"tag":74,"props":1565,"children":1566},{"style":87},[1567],{"type":25,"value":101},{"type":20,"tag":74,"props":1569,"children":1570},{"style":309},[1571],{"type":25,"value":1572},":",{"type":20,"tag":74,"props":1574,"children":1575},{"style":87},[1576],{"type":25,"value":1577}," CustomerTypes",{"type":20,"tag":74,"props":1579,"children":1581},{"style":1580},"--shiki-default:#939F91;--shiki-dark:#F8F8F2",[1582],{"type":25,"value":30},{"type":20,"tag":74,"props":1584,"children":1585},{"style":114},[1586],{"type":25,"value":1587},"values",{"type":20,"tag":74,"props":1589,"children":1590},{"style":87},[1591],{"type":25,"value":1592},"())\n",{"type":20,"tag":21,"props":1594,"children":1595},{},[1596],{"type":25,"value":1597},"One of the rare occasions Java is more concise than C#, obviously ;)",{"type":20,"tag":482,"props":1599,"children":1600},{},[1601],{"type":25,"value":486},{"title":9,"searchDepth":270,"depth":270,"links":1603},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8203.md","comments/using-linq-to-foreach-over-an-enum-in-c/8203.md","comments/using-linq-to-foreach-over-an-enum-in-c/8203",{"_path":1608,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":1609,"description":1610,"id":1611,"name":926,"email":927,"avatar":928,"url":929,"date":1612,"body":1613,"_type":489,"_id":1631,"_source":491,"_file":1632,"_stem":1633,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8199","8199","Good question!",8199,"2008-04-10T19:56:37",{"type":17,"children":1614,"toc":1629},[1615,1619,1624],{"type":20,"tag":21,"props":1616,"children":1617},{},[1618],{"type":25,"value":1610},{"type":20,"tag":21,"props":1620,"children":1621},{},[1622],{"type":25,"value":1623},"LINQ uses some specific compiler magic for the select/in/where/order keywords and also has a bunch of classes in the System.Linq namespace.",{"type":20,"tag":21,"props":1625,"children":1626},{},[1627],{"type":25,"value":1628},"To achieve the functionality requires these classes use Extension methods quite extensively.  It also takes advantage of Lambda expressions, anonymous types and is demonstrated often using type inference, all C# 3.0 features!",{"title":9,"searchDepth":270,"depth":270,"links":1630},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8199.md","comments/using-linq-to-foreach-over-an-enum-in-c/8199.md","comments/using-linq-to-foreach-over-an-enum-in-c/8199",{"_path":1635,"_dir":513,"_draft":6,"_partial":6,"_locale":7,"title":1636,"description":1637,"id":1638,"name":1639,"email":1640,"avatar":1641,"url":1642,"date":1643,"body":1644,"_type":489,"_id":1657,"_source":491,"_file":1658,"_stem":1659,"_extension":494},"/comments/using-linq-to-foreach-over-an-enum-in-c/8198","8198","Great post and valuable information - bookmarked and will be used in the future. :)",8198,"Guy","wildfiction@gmail.com","https://www.gravatar.com/avatar/d9f2c02c23a3013166710a1d24bca056?r=pg&d=retro","https://guyellisrocks.com/","2008-04-10T19:26:18",{"type":17,"children":1645,"toc":1655},[1646,1650],{"type":20,"tag":21,"props":1647,"children":1648},{},[1649],{"type":25,"value":1637},{"type":20,"tag":21,"props":1651,"children":1652},{},[1653],{"type":25,"value":1654},"Question: Is it actually the power of LINQ that you're using? i.e. Are extension methods part of LINQ or are they part of C# 3.0?",{"title":9,"searchDepth":270,"depth":270,"links":1656},[],"content:comments:using-linq-to-foreach-over-an-enum-in-c:8198.md","comments/using-linq-to-foreach-over-an-enum-in-c/8198.md","comments/using-linq-to-foreach-over-an-enum-in-c/8198",1779264587343]