7 Replies - 4338 Views - Last Post: 09 July 2011 - 04:05 AM Rate Topic: -----

#1 xavi8808  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 13-October 10

Problem with writing to the console

Posted 08 July 2011 - 04:14 AM

I have a problem with writing to the console.
When i try run my application that write to the console for example
Console.WriteLine("HELLOWORLD");

I see the results for a second and it goes off. What could be the problem?
XV
Is This A Good Question/Topic? 0
  • +

Replies To: Problem with writing to the console

#2 BigR1983  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 221
  • Joined: 12-April 10

Re: Problem with writing to the console

Posted 08 July 2011 - 04:20 AM

you need to add a
Console.ReadLine();



the reason for this is because the program ends after you are writing to the console. by adding the line i mentioned, you are telling the program to wait until a key is pressed to continue on.

Hope that helps.
Was This Post Helpful? 2
  • +
  • -

#3 Vishu Sukhdev  Icon User is offline

  • D.I.C Head

Reputation: 38
  • View blog
  • Posts: 150
  • Joined: 19-February 10

Re: Problem with writing to the console

Posted 08 July 2011 - 04:24 AM

Hi,
You can use
Console.Read();


at of end of main function()
Was This Post Helpful? 1
  • +
  • -

#4 xavi8808  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 13-October 10

Re: Problem with writing to the console

Posted 08 July 2011 - 04:53 AM

They both work.
I had an interactive code that was using the read()/readLine() methods and i noticed the prompt stay on but i did not know that was the solution.
Thanks again
Was This Post Helpful? 0
  • +
  • -

#5 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: Problem with writing to the console

Posted 08 July 2011 - 06:44 AM

I usually prefer ReadKey. It's the equivalent of "Press Any Key to Continue."
Was This Post Helpful? 0
  • +
  • -

#6 BigR1983  Icon User is offline

  • D.I.C Head

Reputation: 57
  • View blog
  • Posts: 221
  • Joined: 12-April 10

Re: Problem with writing to the console

Posted 08 July 2011 - 11:27 AM

But where is the any key.....
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4314
  • View blog
  • Posts: 7,472
  • Joined: 08-June 10

Re: Problem with writing to the console

Posted 08 July 2011 - 11:58 AM

"There isn't any any key. Whew, all this computer hacking is making me thirsty. Better order a TAB. Wait, no time for that now, the computer's starting!"
Was This Post Helpful? 1
  • +
  • -

#8 DON RIKO  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 1
  • Joined: 30-October 10

Re: Problem with writing to the console

Posted 09 July 2011 - 04:05 AM

View Postxavi8808, on 08 July 2011 - 04:14 AM, said:

I have a problem with writing to the console.
When i try run my application that write to the console for example
Console.WriteLine("HELLOWORLD");

I see the results for a second and it goes off. What could be the problem?
XV

Press ctrl and f5 and the window should stay open.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1