• 0

[C#] Console Application


Question

Hello All,

I'm new to write C# console apps. I have:

static void Main(string[] args)

{

Person p = new Person("Tony", "Allen", 32);

Console.WriteLine(p);

}

struct Person

{

public string firstName;

public string lastName;

public int age;

........

}

When I click the 'play' button in Visual Studio the console window pops up and displays what it should, but closes immediately. How do i keep the window open until I type exit or something of my choice?

Link to comment
https://www.neowin.net/forum/topic/474979-c-console-application/
Share on other sites

6 answers to this question

Recommended Posts

  • 0

Add a Console.ReadLine(); after the line Console.WriteLine(p);

That will mean you then have to type something and press enter to cause the program to exit.

static void Main(string[] args)
{
Person p = new Person("Tony", "Allen", 32);
Console.WriteLine(p);
Console.ReadLine();			  //  Program wont exit until you type something and press enter

}
struct Person
{
public string firstName;
public string lastName;
public int age;
........
}

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.