views:

35

answers:

3

The following works fine in c# (assuming value is an object):

if (value is DateTime)

What is the equivalent check for VB.NET?

+2  A: 

C#

if (value.GetType() == typeof(DateTime)) {}

VB.NET (so the converters tell me)

If value.[GetType]() = GetType(DateTime) Then
    '...
End If
Brad
Close...but not quite; although you did help me arrive upon the solution: If value.GetType() Is GetType(DateTime) Then
DanP
This will fail if value is Nothing
JaredPar
This doesn't allow for polymorphism, so isn't the strict equivalent of the C# in the question.
LukeH
+7  A: 

The VB.Net equivalent is

If TypeOf(value) Is DateTime Then
tnyfst
+1, this is the most idiomatic solution
JaredPar
A: 

If TypeOf value Is DateTime Then

klausbyskov