<p>I have a list of <code>Foo</code>. Foo has properties <code>Bar</code> and <code>Lum</code>. Some <code>Foo</code>s have identical values for <code>Bar</code>. How can I use lambda/linq to group my <code>Foo</code>s by <code>Bar</code> so I can iterate over each grouping's <code>Lum</code>s?</p>

[{'answer_id': 46142, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 2, 'selected': False, 'text': '<pre><code>var q = from x in list\n        group x by x.Bar into g\n        select g;\n\nforeach (var group in q)\n{\n    Console.WriteLine("Group " + group.Key);\n    foreach (var item in group)\n    {\n        Console.WriteLine(item.Bar);\n    }\n}\n</code></pre>\n'}, {'answer_id': 47308, 'author': 'aku', 'author_id': 1196, 'author_profile': 'https://Stackoverflow.com/users/1196', 'pm_score': 3, 'selected': True, 'text': '<p><a href="https://stackoverflow.com/questions/46130/how-do-i-group-in-memory-lists#46317">Deeno</a>,</p>\n\n<p>Enjoy:</p>\n\n<pre><code>var foos = new List&lt;Foo&gt; {\n   new Foo{Bar = 1,Lum = 1},\n   new Foo{Bar = 1,Lum = 2},\n   new Foo{Bar = 2,Lum = 3},\n};\n\n// Using language integrated queries:\n\nvar q = from foo in foos\n        group foo by foo.Bar into groupedFoos\n        let lums = from fooGroup in groupedFoos\n                   select fooGroup.Lum\n        select new { Bar = groupedFoos.Key, Lums = lums };\n\n// Using lambdas\n\nvar q = foos.GroupBy(x =&gt; x.Bar).\n            Select(y =&gt; new {Bar = y.Key, Lums = y.Select(z =&gt; z.Lum)});\n\n\nforeach (var group in q)\n{\n    Console.WriteLine("Lums for Bar#" + group.Bar);\n    foreach (var lum in group.Lums)\n    {\n        Console.WriteLine(lum);\n    }\n}\n</code></pre>\n\n<p>To learn more about LINQ read <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx" rel="nofollow noreferrer">101 LINQ Samples</a></p>\n'}]
['https://Stackoverflow.com/questions/46130', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1946/']