Click here to Skip to main content
15,892,072 members
Articles / Artificial Intelligence

Recursive methods using C#

Rate me:
Please Sign up or sign in to vote.
4.43/5 (74 votes)
23 Apr 2013CPOL4 min read 905.6K   2.9K   91  
For beginners, Recursive introduction, Examples, Benefits and Defects. A part of Data structure.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestConsole.Controls
{
    public class Progress
    {
        public int X { get; set; }
        public int Y { get; set; }        

        public Progress (int x, int y)
        {
            this.X = x;
            this.Y = y;
        }


        private System.Threading.Thread mainThread;

        public void Start()
        {
            mainThread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(
         (object o) =>
         {
             FireProgress(this.X, this.Y);
         }));

            mainThread.Start();
        }

        public void Stop()
        {
            mainThread.Abort();
            Console.BackgroundColor = ConsoleColor.Black;
            Console.ForegroundColor = ConsoleColor.Black;
            Console.CursorLeft = this.X;
            Console.CursorTop = this.Y;

            Console.Write("                                                  ");

            Console.ForegroundColor = ConsoleColor.Gray;
            Console.CursorLeft = 0;
            Console.CursorTop = 0;
        }

        private static void FireProgress(int x, int y)
        {
            int step = 2;

            Console.CursorTop = y;
            Console.CursorLeft = x;
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write("Please wait ");
            int k = x + 12;
            while (true)
            {
                Console.CursorTop = y;
                Console.CursorLeft = k;
                Console.BackgroundColor = (step == 2) ? ConsoleColor.White : ConsoleColor.Black;
                Console.Write(" ");

                k += step;
                System.Threading.Thread.Sleep(100);
                if (k > 32 + x)
                    step = -2;
                if (k <= x + 12)
                    step = 2;
            }
        }
    }
    public class Point
    {
        public int X { get; set; }
        public int Y { get; set; }

        public Point(int x, int y)
        {
            this.X = x;
            this.Y = y;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Iran (Islamic Republic of) Iran (Islamic Republic of)
Microsoft Certified Technology Specialist (MCTS)


"شاهین خورشیدنیا"


Nobody is perfect and neither am I, but I am trying to be more professional. In my humble opinion, you have to develop your skills, as long as you are responsible for developing even a tiny part of a sustainable software. That makes this job so special to me.

Comments and Discussions