开发者

how to divide list in parts from a list by comparison on the instance inside the list

suppose my list<struct>

in list some struct 开发者_JAVA技巧have the date 31 january

some have date 5 march

some have 12 august then

i want to make a list of all same date struct

how i can do this in c#


Assume your struct looks like this:

struct YourStruct 
{
    DateTime DateProperty { get; set; }
}

Then you can use GroupBy to get the dates:

List<YourStruct> list = ....;
var dates = list.GroupBy(s => s.DateProperty.Date);

Group by groups on unique values, so you need to group on the Date property of the DateTime instance. The code above will return an IEnumerable<IGrouping<DateTime>>, where the key of each group will be the corresponding date.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜