\r
sealed class Util\r
{\r
-// public static char Query(string msg, string selections, char defaultSelection)\r
-// {\r
-// Console.Write(msg);\r
-// string response = Console.ReadLine();\r
-// response.Trim();\r
-// if (response.Length < 1) return defaultSelection;\r
-// int resNum = selections.ToLower().IndexOf(response[0]);\r
-// if (resNum < 0 || resNum >= selections.Length) {\r
-// return Query(msg, selections, defaultSelection);\r
-// } else {\r
-// return selections[resNum];\r
-// }\r
-// }\r
+ public static char Query(string msg, string selections, char defaultSelection)\r
+ {\r
+ int resNum = -1;\r
+ while (resNum < 0) { \r
+ Console.Write(msg);\r
+ string response = Console.ReadLine();\r
+ response = response.Trim().ToLower();\r
+ if (response.Length < 1) return defaultSelection;\r
+ resNum = selections.ToLower().IndexOf(response[0]);\r
+ }\r
+ return selections[resNum];\r
+ }\r
\r
public static bool Confirm(string msg, bool defaultSelection)\r
{\r
- Console.Write(msg);\r
- string response = Console.ReadLine();\r
- \r
- switch (response.ToLower())\r
- {\r
- case "y":\r
- return true;\r
- case "n":\r
- return false;\r
- default:\r
- return defaultSelection;\r
- }\r
+ return Query(msg, "yn", defaultSelection? 'y' : 'n') == 'y';\r
}\r
}\r
}\r