Posted by talgiladi on 11/1/2009 12:28 PM | Comments (0)

It starts with a random question, but continues with a well designed pattern...

 

static void Main(string[] args)

        {

 

            string source = null;

            while (true)

            {

                if (source == null)

                {

                    source = GetTheQuestionThatMostInterestsMeNow();

                }

                Console.WriteLine("Why " + source + "?");

                var answer = Console.ReadLine();

                var nextQuestion = ThinkDeeplyAboutTheAnswerAndGetTheNextQuestion(answer);

                source = nextQuestion ?? source;

            }

        }

 

        private static string GetTheQuestionThatMostInterestsMeNow()

        {

            return "are the birds singing";

        }

 

        private static string ThinkDeeplyAboutTheAnswerAndGetTheNextQuestion(string answer)

        {

            string result = null;

            if (answer != null)

            {

                int index;

                if ((index = answer.IndexOf("because", StringComparison.OrdinalIgnoreCase)) > -1)

                {

                    answer = answer.Substring(index + "because".Length);

                }

                result = answer;

            }

            return result;

        }

 

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5