Is there a way to get IsDate (Date) to return as false?

I look at the code in VB.net and in the check object they wrote the following

If Not IsDate(Entity.SelectedDate) Then
            ErrorList.Add(New CValidationError("MainReport", "Please select a weekend date"))

SelectedDate is of type Date. It seems to me that it will never be possible to achieve this state. It's true?

+3
source share
6 answers

Here is what I see in Reflector :

Public Shared Function IsDate(ByVal Expression As Object) As Boolean
    Dim time As DateTime
    If (Expression Is Nothing) Then
        Return False
    End If
    If TypeOf Expression Is DateTime Then
        Return True
    End If
    Dim str As String = TryCast(Expression,String)
    Return ((Not str Is Nothing) AndAlso Conversions.TryParseDate(str, (time)))
End Function

Now the question is: if passed Date(VB.NET keyword for values DateTime), can this method ever return false?

No.

If (Expression Is Nothing)

This value will never be true for a type with a short value.

If TypeOf Expression Is DateTime

This will always be if the method is explicitly passed a Date.

TypeOf A Is B false, B A ( ), , true, DateTime, , .

, .

, IsDate String Object, ; - - SelectedDate, Date, .

+3

IsDate true , : http://msdn.microsoft.com/en-us/library/00wf8zk9%28VS.80%29.aspx

true,

dim myDate as Date
myDate = Nothing
IsDate(myDate)

http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/3f70ef9e-79d0-4c89-ac33-ea16829e8298 :

, Date , , Nothing Date (. , ).

IsDate (date) true.

, IsDate VB - , ( , , ). " ", , Visual Studio. Microsoft.VisualBasic, , true.

+1

, - . SelectedDate OnSelectionChanged. Null. , , , . , .

0

. SelectedDate Date. , .

0

, , DateTime.DayOfWeek ?

0

IsDate Microsoft.VisualBasic; , . , ; .

0

Source: https://habr.com/ru/post/1755830/


All Articles