开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜