I have two questions:
Date and DateTime : Are they different or same in VB ?
DateTime can be assigned Nothing in VB, where as it cannot be assigned null in C#. Being a structure it cannot be null. So why is it being allowed in VB ?
---VB.NET-----
Module Module1
    Sub Main()
        Dim d As Date = Nothing
        Dim dt As DateTime = Nothing
        d = CType(MyDate, DateTime)
    End Sub
    Public ReadOnly Property MyDate As DateTime
        Get
            Return Nothing
        End Get
    End Property
End Module
---C#.NET-----
class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = null;//compile time error            
        }
    }
                Nothing in VB.NET is not the same as null in C#. It has also the function of default in C# and that is what happens when you use it on a structure like System.DateTime.
So both, Date and DateTime refer to the same struct System.DateTime and
Dim dt As Date = Nothing 
actually is the same as
Dim dt = Date.MinValue
or (in C#)
DateTime dt = default(DateTime);
                        In c# You can use default keyword
DateTime dt = default(DateTime);
Date and DateTime are same in VB.NET. Date is just alias of DateTime
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