Michael,
First of all let me welcome you to the wonderfull world of .NET and to
congratulate you on your excellent choise of programming langauge
To
get back to your problem; the short answer to your question is that your
application runs out of code to execute and there for terminates. If you
were to add a loop such as a while-loop then the application would stay
in that loop thus not running out of code to execute.
The easy, and most common way, to prevent the application to terminate
before you want to (so you perhaps can read the output it created) you
could add Console.ReadLine() at the end of your Main method. This tells
the console application to wait for you to input something, and not continue
until you have done so. This makes your console application pause just
before it is about to terminate
Try the following:
[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.ReadLine();
}
And you should see that your application does not end without you pressing
enter. The reason most books does not include this is because they expect
you to execute it from the .NET Command Prompt (like a DOS prompt but
with .NET environment variables set) where the window still stays open when
the application has finished executing.
Hope this helps,
//Andreas
Michael W said:
I'm a complete newbie at programming. I chose to learn C# as my
programming language. Every book I purchase starts with console
applications. Each time I try to run the apps that I build, it will only
display for a few seconds then it will disappear? I'm running Windows XP
and have VS.net. Is there some way that I can view the output of my console
applications with out it shutting off on me? I'm getting discouraged
because I want to build Windows apps and not console apps right now? I
can't seem to run any command line apps. I'm stuck because these books
teach you the basics of the language using console apps. I want to skip
past this but I miss out on so much. Please help!!!!