[C#]Real time example of recursion
페이지 정보
작성자 sbLAB 댓글 0건 조회 4,388회 작성일 18-07-25 17:35본문
※ recursion 를 이해할때는 단일의 자신 펑션을 바라보면서 파라미터값이 다시 들어간다는 생각하면
복잡하다.
recursion 펑션을 만날때, 똑 같은
FindFiles 함수가 별도로 메모리에 추가 생성 된다고 이해하자.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace recursion
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("please enter path");
string path = Console.ReadLine();
FindFiles(path);
Console.ReadKey();
}
//example of recursion
private static void FindFiles(string path)
{
foreach (string fileName in Directory.GetFiles(path))
{
Console.WriteLine(fileName);
}
foreach (string directory in Directory.GetDirectories(path))
{
FindFiles(directory);
}
}
}
}
댓글목록
등록된 댓글이 없습니다.