suppose my list<struct>
in list some struct 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.