C# 可为空的日期时间列表到不可为空的日期时间列表

C# 可为空的日期时间列表到不可为空的日期时间列表,c#,C#,我有一个可为空的日期时间列表。我需要通过排除空值将其过滤到不可为空的日期时间列表 var d = NullableDateTimeList; ??//var nonNullableList = d.Where(p => p.DateX.HasValue).Select(p => p.Datex); 我该怎么做呢。谢谢。只需选择.Value var nonNullableList = d.Where(p => p.DateX.HasValue).Select(p => p

我有一个可为空的日期时间列表。我需要通过排除空值将其过滤到不可为空的日期时间列表

var d = NullableDateTimeList;
??//var nonNullableList = d.Where(p => p.DateX.HasValue).Select(p => p.Datex);

我该怎么做呢。谢谢。

只需选择
.Value

var nonNullableList = d.Where(p => p.DateX.HasValue).Select(p => p.DateX.Value);

在调用
ToList()
之前,必须从
Nullable
中选择
Vaue

List nonNulls=NullableDateTimeList
.Where(d=>d.DateX.HasValue)
.Select(d=>d.DateX.Value)
.ToList();

非常接近,选择可为空的
日期时间时,只需添加
.Value
属性即可:

var nonNullableList = d.Where( p => p.DateX.HasValue )
    .Select( p => p.DateX.Value )
    .ToList();
var nonNullableList = d.Where( p => p.DateX.HasValue )
    .Select( p => p.DateX.Value )
    .ToList();