AleAng
AleAng

Reputation: 71

How do I make my console window stop making me type enter in Visual Studio?

I have a simple application to practice C# but my console window makes me type enter instead of showing the whole result at once and I don't think that there is anything wrong with the code. I have pasted my code here anyways. I just don't want to have to type enter every time I want to see something in the console window. How do I change this?

namespace CallingMethods
{
    class Program
    {
        static void Main(string[] args)
        {
            NameGame("John", "Smith");
            int myNumber = NumberGame(1234);
            Console.WriteLine(myNumber); Console.ReadLine();
        }

        public static void NameGame(string firstName, string lastName)
        {
            char[] firstNameArray = firstName.ToCharArray();
            Array.Reverse(firstNameArray);

            char[] lastNameArray = lastName.ToCharArray();
            Array.Reverse(lastNameArray);

            string result = " ";

            foreach (char item in firstNameArray)
            {
                result+=item;
            }

            result += " ";

            foreach (char item in lastNameArray)
            {
                result += item;
            }
            Console.WriteLine(result); Console.ReadLine();
        }

        private static int NumberGame(int v)
        {
            return (v*2) * 100;
        }





}

}

Upvotes: 1

Views: 52

Answers (1)

arrowd
arrowd

Reputation: 34411

You have Console.ReadLine(); at the end of NameGame() and the result is printed after this call. Due to this you need to enter a line before it gives you result.

Upvotes: 3

Related Questions