C # why does it skip my console.readline ()?

So, the program works correctly, but for some reason the second time it misses the Console.ReadLine () prompt in general. I went through debug and confirmed that this is not a loop problem, as it does introduce this method, showing WriteLine, and then completely skips ReadLine, returning an empty line to Main (), causing it to exit. What a deuce? Any ideas?

here is the code.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LAB4B
{
    class Program
    {
        static void Main(string[] args)
        {
            string inString;
            ArrayList translatedPhrase = new ArrayList();

            DisplayInfo();
            GetInput(out inString);

            do
            {
                GetTranslation(inString, translatedPhrase);
                DisplayResults(inString, translatedPhrase);
                GetInput(out inString);
            } while (inString != "");

        }

        static void DisplayInfo()
        {
            Console.WriteLine("*** You will be prompted to enter a string of  ***");
            Console.WriteLine("*** words. The string will be converted into ***");
            Console.WriteLine("*** Pig Latin and the results displayed. ***");
            Console.WriteLine("*** Enter as many strings as you would like. ***");
        }

        static void GetInput(out string words)
        {

            Console.Write("\n\nEnter a group of words or ENTER to quit: ");
            words = Console.ReadLine();            
        }

        static void GetTranslation(string originalPhrase, ArrayList translatedPhrase)
        {
            int wordLength;                       
            string[] splitPhrase = originalPhrase.Split();

            foreach (string word in splitPhrase)
            {
                wordLength = word.Length;
                translatedPhrase.Add(word.Substring(1, wordLength - 1) + word.Substring(0, 1) + "ay");
            }          




        }

        static void DisplayResults(string originalString, ArrayList translatedString)
        {
            Console.WriteLine("\n\nOriginal words: {0}", originalString);
            Console.Write("New Words: ");
            foreach (string word in translatedString)
            {
                Console.Write("{0} ", word);
            }

            Console.Read();
        }

    }
}
0
source share
3 answers

- Console.Read() DisplayResults. . ENTER ( - ) Console.Read(), , - Console.ReadLine() GetInput(). ENTER, Console.ReadLine() .

+9

Console.Read() DisplayResults Console.ReadLine(). , , .

+2

. do-while, , inString .

Btw,

do
{
} while (!String.IsNullOrEmpty(inString));

.

0

All Articles