Reputation: 27
i imagine something like this:
prompt> checkprice
price of foo is 42$
prompt>
To run multiple commands.
Upvotes: 1
Views: 186
Reputation: 2810
Maybe this
//this is your price variable
static int price = 42;
//function to check it
static void CheckPrice()
{
Console.WriteLine("price of foo " + price + "$");
}
static void Main()
{
bool exit = false;
do
{
//write at begin ">"
Console.Write(">");
//wait for user input
string input = Console.ReadLine();
// if input is "checkprice"
if (input == "checkprice") CheckPrice();
if (input == "exit") exit = true;
} while (!exit);
}
Upvotes: 0
Reputation: 1568
Do while until type a specific command like "exit":
static void Main(string[] args) {
var line = System.Console.ReadLine().Trim();
while(line!="exit") {
myOperationCommand(line);
line = System.Console.ReadLine().Trim(); // read input again
}
System.Console.WriteLine("End!\n");
}
// Do some operation...
static void myOperationCommand(string line) {
switch(line) {
case "checkprice":
System.Console.WriteLine("price of foo is 42$");
break;
default:
System.Console.WriteLine("Command not reconized: " + line);
break;
}
}
Upvotes: 1
Reputation: 17407
Something like:
while(true) {
Console.Write("prompt>");
var command = Console.ReadLine();
if (command == "command1") doSomething();
else if (command == "command2") doSomethingElse();
...
else if (command == "quit") break;
}
Upvotes: 1