C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2722
Number of posts: 5749

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Interactive Hello World question Posted by BulletHoles on 1 Nov 2009 at 11:23 AM
I am working through the C# e-book. Here is the code for the part I have a question about:

using System.Text;

namespace InteractiveHelloWorld
{
class MainClass
{
static void Main(string[] args)
{
Console.Write("Please enter your name: ");
string name = Console.ReadLine();
Console.WriteLine
("Hello {0}, Good Luck in C#", name);
}
}
}

When I click Start Debugging in Visual Studio 2008, it pops up a command prompt window asking me my name, like it should. But when I type in my name and hit enter, it then displays the next line (Hello Marc, Good Luck in C#) and then immediately closes.

Is it supposed to close so fast like this? It only displays the second line for like a 10th of a second before closing. I can hardly even read the second line before it closes. Am I doing something wrong or is this normal?

Thanks


Report
Re: Interactive Hello World question Posted by Xelalem on 13 Nov 2009 at 12:16 PM
Just add this next to the
Console.WriteLine("Hello {0}, Good Luck in C#", name);

*********************

Console.ReadKey(true);

//This should solve your problem



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.