Recursion in C#

Use of recursion in C#.

The function that calls itself is called as recursion.

Real time example:- When and where do we use the recursion in our projects?
A simple answer to this question is, "To find all the files in a folder, and in all the sub folders in the hierarchy."
Given below is a good example of the recursion.

private static void Findfiles(string path)

{

   foreachstring filename in directory.getFile(path))

   {

      console.writeline(Filename); 

   } 

   foreachstring filename in directory.getDirectories(path)) 

   {

      //find file calling itself

      findFile(directory);

   }

Ebook Download
View all
Learn
View all