string root = @"C:\";
//old way--get all strings up front
DirectoryInfo di = new DirectoryInfo(root);
DirectoryInfo[] directories = di.GetDirectories("*",
SearchOption.AllDirectories);
//new in .Net 4--use an enumerator
di = new DirectoryInfo(root);
//to get files, use di.EnumerateFiles with the same type of arguments
IEnumerable<DirectoryInfo> dirInfo = di.EnumerateDirectories("*",
SearchOption.AllDirectories);
foreach (DirectoryInfo info in dirInfo)
{
Console.WriteLine(info.Name);
}