code_junkie

C#: How to detect arguments typed into console application?

Nov 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. Console.WriteLine("Welcome To Food Hut");
  4. Console.ReadLine();
  5.  
  6. // if readline equals to /help then display some help text.
  7.  
  8.  
  9. // if /food command is typed, read first argument after /food Pizza, -t TheTopping
  10. // and -p ForWhatToDrink
  11.  
  12. // and then display, 'So you would like a Pizza with Pepperoni and Pepsi to drink?'
  13. }
  14.  
  15. static void Main(string[] args)
  16. {
  17. Arguments cmdline = new Arguments(args);
  18.  
  19. Console.WriteLine(cmdline["name"]);
  20. }
  21.  
  22. string input = Console.ReadLine();
  23. if (input == "/help") { }
  24. else if (input.StartsWith("/food")) { }
  25. else { //... }
  26.  
  27. Food:
  28. 1) Tofu
  29. 2) Tempeh
  30. 3) Seitan
  31. 4) Soup
  32.  
  33. Choice (1-4)? [users input]
  34.  
  35. Drink:
  36. 1) Pepsi
  37. 2) Coffee
  38. 3) Water
  39. 4) Tea
  40. 5) Juice
  41.  
  42. Choice (1-5)? [users input]
  43.  
  44. input = Console.ReadLine();
  45. string[] commands = input.Split(' ');
  46. if(commands[0] == "/food")
  47. {
  48. if(commands[1] == "Pizza");
  49. .....
  50. }
Add Comment
Please, Sign In to add comment