I am a c#/asp.net developer and I am having to work on a VB/asp.net.
I started out with VB.NET but after years away from it I’m getting confused with the syntax.
I have two variables
Dim originalDate as DateTime?
Dim newDate as DateTime?
Both nullable datetimes, originalDate is a nullable date I am getting from the database and newDate time is set in code, I need to compare them, they can either both have dates, neither have dates or one have and one not.
I have a bit of code as follows:
if origEndDate = origEndDate then
When both origEndDate and origEndDate are “nothing” this statement is false (well when I run it in the watch window it comes back as nothing)!
I don’t understand why this is the case because I was under the impression doing an “=” compares the two values and as they are the same surely it should be true?
Can someone explain what I am doing wrong? What syntax should I be using as in C# I can do the above as so:
if (origEndDate == origEndDate) { }
and it will come back as true.
Confused!
Thanks for any help!
Try
originalDate.Equals(newDate)maybe?(No, this will not cause an NRE when either date is null, since the variables are actually of the value type
Nullable(Of DateTime)and are therefore not actually null until they are boxed.)