If I define a list as
public class ItemsList
{
public string structure { get; set; }
public string Unit { get; set; }
public double Dim { get; set; }
public double Amount { get; set; }
public int Order { get; set; }
public string Element { get; set; }
}
List<ItemsList> _itemsList = new List<ItemsList>();
I’m trying to get the a distinct count of structures in a Lookup with structure as the key and count of structure as the value.
At the moment I have
var sCount = from p in _itemsList
group p by p.Structure into g
select new { Structure = g.Key, Count = g.Count() };
but this just returns the data as an anonymous type. Can someone please help me with the syntax to get this into a Lookup using .ToLookup?
I suspect you actually want:
You can still count the items for any group:
… but you’ve also got the values within each group.
If you really just want the count, then it sounds like you don’t want a lookup at all – you want a
Dictionary, which you can get with: