zoukankan      html  css  js  c++  java
  • 递归例子

    public class Recursion
    {
    /// <summary>
    /// 找出全部的子文件夹
    /// </summary>
    /// <param name="rootPath">根目录</param>
    /// <returns></returns>
    public static List<DirectoryInfo> GetAllDirectory(string rootPath)
    {
    List<DirectoryInfo> directoryList = new List<DirectoryInfo>();
    DirectoryInfo directory = new DirectoryInfo(rootPath);
    GetChildDirectory(directoryList, directory);

    return directoryList;
    }


    /// <summary>
    /// 找出某个文件夹的子文件夹,,放入集合
    ///
    /// 递归:方法自身调用自身
    /// </summary>
    /// <param name="directoryList"></param>
    /// <param name="parentDirectory"></param>
    private static void GetChildDirectory(List<DirectoryInfo> directoryList, DirectoryInfo parentDirectory)
    {
    directoryList.AddRange(parentDirectory.GetDirectories());
    if (parentDirectory.GetDirectories() != null && parentDirectory.GetDirectories().Length > 0)
    {
    foreach (var directory in parentDirectory.GetDirectories())
    {
    GetChildDirectory(directoryList, directory);
    }
    }
    }
    }

  • 相关阅读:
    [NOIP2015] D1T2 信息传递
    Codeforces #447 Div.2 Tutorial
    python进阶
    Vue入门
    python基础
    python介绍
    React笔记_(3)_react语法2
    React笔记_(2)_react语法1
    React笔记_(1)_react概述
    webpack笔记_(3)_First_Project
  • 原文地址:https://www.cnblogs.com/anyihen/p/12773370.html
Copyright © 2011-2022 走看看