Как сделать простые команды? - C#
Формулировка задачи:
Чего не хватает?
static void Main(string[] args)
{
bool _break = false;
while (! _break)
{
Console.WriteLine("Введите команду: ");
string _comand = Console.ReadLine();
switch (_comand.ToLower())
{
case "quit":
case "exit":
_break = true;
break;
case "help":
Console.WriteLine("Нет помощи ");
break;
default:
Console.WriteLine("Такой команды нет");
break;
}
К командам ещё бы параметры добавить.
Решение задачи: «Как сделать простые команды?»
textual
Листинг программы
class Program
{
static void Main(string[] args)
{
bool _break = false;
while (!_break)
{
Console.Write("Введите команду: ");
string _command = Console.ReadLine();
switch (_command.ToLower())
{
case "quit":
case "exit":
_break = true;
break;
case "help":
Console.WriteLine("Справка для слабаков, думай сам.");
break;
case "print":
Console.WriteLine("Здесь будет ваш текст.");
break;
case "print color":
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("Ваш цветной текст.");
Console.ResetColor();
break;
case "time":
Console.WriteLine(System.DateTime.Now.ToLongTimeString());
break;
case "copy":
Console.WriteLine("Введите строку: ");
string _s1 = Console.ReadLine();
Console.WriteLine("Копия вашей строки: ");
Console.WriteLine(string.Copy(_s1 ) );
break;
case "longCircle":
{
Console.WriteLine("Введите радиус окружности: ");
double r = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(longCircle(r));
}
break;
case "sort":
{
Console.WriteLine("Введите строку: ");
string s = Console.ReadLine();
char[] m = s.ToCharArray();
Array.Sort(m);
s = new string(m);
Console.WriteLine("Отсортированная строка: ");
Console.WriteLine(s);
}
break;
default:
Console.Write("Такой команды нет!");
break;
}
}
Console.Write("Нажмите любую клавишу для продолжения.");
Console.ReadKey();
}
static double longCircle(double r)
{
return 2 * Math.PI * r;
}
}
}