fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. var root = GetDemoRoot();
  8. var folderName = browse(root);
  9. Console.WriteLine("you got: {0}", folderName);
  10. }
  11.  
  12. private static string browse(Folder folder)
  13. {
  14. string folderName = null;
  15. Console.WriteLine("now at {0}", folder.Name);
  16.  
  17. if (folder.Folders != null)
  18. {
  19. for (var i = 0; i < folder.Folders.Length; i++)
  20. {
  21. browse(folder.Folders[i]);
  22. folderName = folder.Folders[i].Name;
  23. }
  24. }
  25. return folderName;
  26. }
  27.  
  28. private static Folder GetDemoRoot()
  29. {
  30. return new Folder
  31. {
  32. Name = "root",
  33. Folders = new[]
  34. {
  35. new Folder
  36. {
  37. Name = "One",
  38. Folders = new[]
  39. {
  40. new Folder
  41. {
  42. Name = "OnePointTwo"
  43. }
  44. }
  45. },
  46. new Folder
  47. {
  48. Name = "Two",
  49. Folders = new[]
  50. {
  51. new Folder
  52. {
  53. Name = "TowPointOne",
  54. Folders = new[]
  55. {
  56. new Folder
  57. {
  58. Name = "TowPointOnePointTwo"
  59. }
  60. }
  61. }
  62. }
  63. },
  64. new Folder
  65. {
  66. Name = "This is the last folder"
  67. }
  68. }
  69. };
  70. }
  71.  
  72. class Folder {
  73. public string Name { get; set; }
  74. //public string[] Items {get; set;}
  75. public Folder[] Folders {get; set;}
  76. }
  77. }
Success #stdin #stdout 0s 131648KB
stdin
Standard input is empty
stdout
now at root
now at One
now at OnePointTwo
now at Two
now at TowPointOne
now at TowPointOnePointTwo
now at This will be empty
you got: This will be empty