简体   繁体   中英

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;
        }





}

}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM