using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo root = new DirectoryInfo(@"c:\temp");
Console.WriteLine(root);
Console.WriteLine();
DirectoryInfo[] folders = root.GetDirectories();
foreach (DirectoryInfo di in folders)
Console.WriteLine(di);
Console.WriteLine();
DirectoryInfo newFolder = root.CreateSubdirectory("New Folder");
Console.WriteLine(newFolder);
Console.ReadLine();
}
}
}
Provides the following output (assuming two folders already exist named test1 and test2 in my temp folder):
c:\temp
test1
test2
c:\temp\New Folder
The ToString() method of root and newFolder returns the full path. Where the ToString() method of the array of DirectoryInfos only return the folder name itself.
Is this intended behavior? I would expect ToString() to return the same string for a given folder regardless how the object was instantiated. If this is intended behavior, what was the reasoning behind this intent?

New Topic/Question
Reply



MultiQuote



|