tags:

views:

15

answers:

2

Why does the following display 12/31/1600 ???

Imports System.IO

Module Module1

Sub Main()
    Dim fi As New FileInfo("DocFiles\phillips_phone_number.txt")
    Console.WriteLine(fi.FullName)
    Console.WriteLine(fi.LastAccessTime.ToShortDateString)
    Console.ReadKey()
End Sub

End Module

A: 

December 31st, 1600 was the date the British East India Company was chartered. Do you have any Indian co-workers who like to play practical jokes?

MusiGenesis
That is so funny, I am Indian :)
Sijin
+1  A: 

It seems that code is not able to find the file, see the documentation for the GetLastAccessTime function in the SDK http://msdn.microsoft.com/en-us/library/system.io.file.getlastaccesstime.aspx

It states,

If the file described in the path parameter does not exist, this method returns 12:00 midnight, January 1, 1601 A.D. (C.E.) Coordinated Universal Time (UTC), adjusted to local time.

Sijin
OK, this one is a candidate for most bizarre .NET library behavior. Why would they return *anything* instead of throwing an exception here, and why return that date in particular? And why return an adjusted local time instead of UTC (making this condition much more difficult to check for)? This is weirder than .NET throwing an OutOfMemoryException when trying to load an invalid Image file.
MusiGenesis
This is a candidate for my .NET gotchas question: http://stackoverflow.com/questions/241134/what-is-the-worst-gotcha-in-c-or-net
MusiGenesis