6

I´m learning C # basic concepts and a question has come up after doing this exercise:

using System;

namespace exercise
{
class MainClass
{
public static void Main (string[] args)
{

console.WriteLine("Type your name");
String name = Console.ReadLine ();

console.WriteLine("Type one city");
String city = Console.ReadLine ();

console.WriteLine("Hello"+ name + "wellcome to " + city )
Console.ReadLine ();

}
}
}

Question: its necessary to put the last
Console.ReadLine ();?Why?

Comments
  • 3
    What @TheCommoner282 said
    Also, at least dotnet core, will wrap it for you, so it doesn't just quits, IF you're in release mode. So some #if DEBUG for that ReadLine() should be good
  • 1
    @TheCommoner282 Ok, I understand what you mean. It's a way to keep the application open,Right?
  • 4
  • 2
    @Kimmax Thanks for the advice : )
  • 1
    When I was learning, this unnecessary readline always bugged me so I used to have an infinte while to keep it open. Dont know if I am the only one or other people got bugged by this too
  • 2
    BTW, next time feel free to remove the line to see what happens.
  • 0
    @Codex404 You are right.Next time I should try to play with the code for myself.

    Thanks for your coment : )
  • 0
    @iCanCode That's good to know. This was an exercise that I saw online but I didn't check it with any IDE so I don't know if it can cause the bug you are talking about.
Add Comment