fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. Console.WriteLine("You have not installed Microsoft SQL Server 2008 R2, do you want to install it now? (Y/N): ");
  8. //var answerKey = Console.ReadKey();
  9. //var answer = answerKey.Key;
  10. var answer = Console.ReadLine();
  11. Console.WriteLine("After key pressed.");
  12. Console.WriteLine("Before checking the pressed key.");
  13. //if(answer == ConsoleKey.N || answer != ConsoleKey.Y)
  14. if (string.IsNullOrEmpty(answer) || string.IsNullOrEmpty(answer.Trim()) || string.Compare(answer.Trim(), "N", true) == 0)
  15. {
  16. Console.WriteLine("The installation can not proceed.");
  17. Console.Read();
  18. return;
  19. }
  20. Console.WriteLine("Success {0}", answer);
  21. }
  22. }
Success #stdin #stdout 0.05s 34760KB
stdin
y
stdout
You have not installed Microsoft SQL Server 2008 R2, do you want to install it now? (Y/N): 
After key pressed.
Before checking the pressed key.
Success y