How can I replace all DateTime?s where the date is null with DateTime.MaxValue?
I have tried:
Array.ConvertAll(myDateTimeArray, a => a = a.HasValue ? a : DateTime.MaxValue);
and also:
myDateTimeArray.Where(a => a == null).ToList().ForEach(a => a = DateTime.MaxValue);
After that I want to do something like:
DateTime minDate = myDateTimeArray.Min(a => a.Value);
but I am getting an InvalidOperationException because a.Value is null...
You can do this:
myDateTimeArray = myDateTimeArray.Select(dt => dt ?? DateTime.MaxValue).ToArray();
This would replace the entire array, not its individual elements. If you need to replace individual elements, use a for loop instead.
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