我有两个问题:
Date
和DateTime
:它们在 VB 中是不同的还是相同的?DateTime
在VB中可以赋值为Nothing,而在C#中不能赋值为null。作为一个结构,它不能为空。那么为什么它在 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
}
}