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.
精彩评论