我有兩個問題:日期時間在VB.NET和C#
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
}
}
查看http://stackoverflow.com/questions/798121/date-vs-datetime – Steve
@musefan:好的,但在VB.NET中,你可以寫Dim Dim As Date? =無「。那有什麼區別? –
@TimSchmelter:非常恰當的命名「暗淡」是不同的。我知道我們很酷的孩子有一個懶惰的'變種',但我對VB的盲目仇恨不需要有理由支持,我只需要確保我盡我所能,並在有機會出現時做出正確的噪音。 .. #CutForVB – musefan