I have a list of nullable date times. I need to filter it down to a non-nullable DateTime list by excuding the null values.
var d = NullableDateTimeList;
??//var nonNullableList = d.Where(p => p.DateX.HasValue).Select(p => p.Datex);
How do I go about doing this. Thanks.
very close, just add the .Value property when selecting the nullable DateTime:
var nonNullableList = d.Where( p => p.DateX.HasValue )
.Select( p => p.DateX.Value )
.ToList();
You have to select the Vaue from the Nullable<DateTime> before you call ToList():
List<DateTime> nonNulls = NullableDateTimeList
.Where(d => d.DateX.HasValue)
.Select(d => d.DateX.Value)
.ToList();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With