示例#1
0
    ///////////////////////////////////////////////////////////////////////////////////
    void VisitDirs()
    {
        var printFiles = Recursion.Action <Queue <string> >(
            (dirs, stack) =>
        {
            if (!dirs.Any())
            {
                stack.Exit();
            }
            else
            {
                string dir = dirs.Dequeue();

                Directory.GetFiles(dir)
                .ForEach(WriteLine);

                Directory.GetDirectories(dir)
                .ForEach(dirs.Enqueue);

                stack.Push(dirs);
            }
        });

        var dirsToVisit = new Queue <string>()
                          .Add(userDocsDir);

        printFiles(dirsToVisit);
    }
示例#2
0
    ///////////////////////////////////////////////////////////////////////////////////
    void WaitForNumOfSeconds()
    {
        var wait = Recursion.Action <int>((count, stack) =>
        {
            if (count == 0)
            {
                stack.Exit();
            }
            else
            {
                Thread.Sleep(1000);
                WriteLine("tick...");
                stack.Push(count - 1);
            }
        });

        wait(5);
    }