我正在尝试在我的UI上设置一个日期范围过滤器,其中包括复选框来指示是否应使用DateTimePicker的值。
Dim fromDate As DateTime? = If(fromDatePicker.Checked, fromDatePicker.Value, Nothing)
将fromDate
设置为Nothing
并不会导致它被设置为Nothing
,而是会被设置为“12:00:00 AM”,因此下面的If
语句会错误地执行过滤,因为startDate
不是Nothing
。
If (Not startDate Is Nothing) Then
list = list.Where(Function(i) i.InvDate.Value >= startDate.Value)
End If
如何确保startDate
获得Nothing
的值?
New Date
作为魔法数字表示“无日期”。 - SSSstartDate
是一个方法中的参数,我将fromDate
传递给它。 - ProfK