How to keep console window open

user1929393 picture user1929393 · Jun 6, 2013 · Viewed 128.9k times · Source

When I run my program, the console window seems to run and close. How to keep it open so I can see the results?

class Program
{
    public class StringAddString       
    {                        
        public virtual void AddString()
        {
            var strings2 = new string[] { "1", "2", "3", "4", "5","6", "7", "8", "9"};

            Console.WriteLine(strings2);
            Console.ReadLine();
        }
    }

    static void Main(string[] args)
    {          
        StringAddString s = new StringAddString();            
    }
}

Answer

TGH picture TGH · Jun 6, 2013

Put a Console.Read() as the last line in your program. That will prevent it from closing until you press a key

static void Main(string[] args)
{
    StringAddString s = new StringAddString();
    Console.Read();            
}