This is from LinqPad (hence the .Dump())
void Main()
{
var k1 = new List<int>(){1,2,3,4,5};
var k2 = new List<int>(){1,2,3,4,5};
var o1 = new A(){k=k1, objectName="o1"};
var o2 = new A(){k=k2, objectName="o2"};
var l = new List<A>();
l.Add(o1);
l.Add(o2);
var b = from a in l
group a.objectName by a.k into g
select new {g.Key, n = String.Join(",",g)};
b.Dump();
}
public class A {
public List<int> k;
public string objectName;
}
The problem is that it doesn't work, the code above yields:
I know why this is happening, it's because the list objects are separate objects, but what I was wondering is if there is a way to tell group by to use content of the list rather than the object instance.