The Directory property may indeed be null . Property implementation is approximately equal
public DirectoryInfo Directory { get { string directoryName = this.DirectoryName; if (directoryName == null) { return null; } return new DirectoryInfo(directoryName); } }
It can definitely return null . Here is a concrete example
var x = new FileInfo(@"c:\"); if (x.Directory == null) { Console.WriteLine("Directory is null");
Jaredpar
source share