Note that there are some explanatory texts on larger screens.

plurals
  1. POProgram reads previous input
    primarykey
    data
    text
    <p>I've just started understanding C# code and wanted to try out a Console Application. Fairly basic, and would involve a loop to carry out some work until the user decides to quit. This is how my program looks for now. </p> <pre><code>public void Method1(string[] args) { if (args.Length != 0) { DoWork(args); ResetValues(); Loop(parameter); } else { Console.WriteLine("No arguments passed"); string helpMsg ... Console.WriteLine(helpMsg); } public void Loop(parameter) { bool wantsContinue = true; while (wantsContinue) { Console.WriteLine("What would you like to do now?\n-Exit\tWrite 'e'\n-Run again\tWrite 'r'"); ConsoleKeyInfo command = Console.ReadKey(); char key = command.KeyChar; switch (key) { case 'e': return; case 'r': Console.WriteLine("Please enter your commands"); string input = Console.ReadLine(); Method1(parameters); break; case 'h': Console.WriteLine(helpMsg); break; default: Console.WriteLine("\nInvalid argument. Enter again"); break; } } } public void MethodContinuous(input) { Console.WriteLine(input); string[] args = input.Split(' '); if (args.Length != 0) { DoWork(args); } else { Console.WriteLine("No arguments passed"); string helpMsg = ... Console.WriteLine(helpMsg); } } </code></pre> <p>However, I am getting a problem which I can't figure out. When the program enters the loop first time, it sets the parameters correctly, but when the loop is continuing, it gives me the user input from the previous run. I'm probably doing something that isn't right, or the Console works a bit differently. Can the expert figure it out?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload