How can I count number of objects in a list with a unique property with linq/lambda?
Let's say I have a
public class MyObject
{
public string Property1;
//other properties
//other properties
}
and then I have a
List<MyObject> objectList
Where Property1 has one value for the first few items, another value for the next few items, 开发者_开发问答etc. How can I count the distinct number of MyObjects based on Property1?
Use GroupBy.
objectList.GroupBy(o => o.Property1);
http://www.codeproject.com/articles/35667/How-to-Use-LINQ-GroupBy.aspx
加载中,请稍侯......
精彩评论