c# - 不同日期列表

标签 c# .net linq date datetime

我有以下代码:

List<DateTime> dates = new List<DateTime>();
//filling the list somehow
dates = dates.Distinct().ToList();

代码基本上可以工作,但我得到了唯一 DateTime 的列表。而且我想获得唯一日期的列表,因为我在这里根本不需要时间。有好的解决办法吗?

我的问题不同于

c# Linq select distinct date time days

因为我实际上并没有查询数据库。我只想过滤列表。

最佳答案

如何使用转换 SELECT

Projects each element of a sequence into a new form.

有点像

dates = dates.Select(x => x.Date).Distinct().ToList();

关于c# - 不同日期列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29942666/

相关文章:

c# - MEF 最佳实践 : Where in the application I create container and where to call Compose()?

.net - 使用 .Net Framework 的空间 anchor (Azure 混合现实服务)

c# - 如何通过将字典值作为过滤器参数来使用 C# 驱动程序查询 MongoDb 集合

c# - 使用通用隐式运算符有什么问题?

c# - 在同一 Controller 上的 Web Api 中多次 POST 调用的最佳实践

c# - 如何在 wpf datagrid 中绑定(bind)行标题?

c# - Linq 查询返回记录列表而不是显示单个记录

c# - 如何在LINQ中执行2次检查

c# - 具有通用方法和属性的两个类

c# - 通过 Entity Framework 分析查询