Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Last active April 20, 2025 10:45
Show Gist options
  • Save StrikerXx798/d3f6a88641672c1722417187b78bd2ee to your computer and use it in GitHub Desktop.
Save StrikerXx798/d3f6a88641672c1722417187b78bd2ee to your computer and use it in GitHub Desktop.
ДЗ: Динамический массив продвинутый
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApp1
{
internal class Program
{
static void Main(string[] args)
{
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
const string ExitCommand = "exit";
const string SumCommand = "sum";
bool isRun = true;
List<int> numbers = new List<int>();
while (isRun)
{
Console.Write("Текущий массив чисел: ");
foreach (int number in numbers)
{
Console.Write($"{number} ");
}
Console.WriteLine();
Console.Write("Введите команду: ");
string command = Console.ReadLine();
switch (command)
{
case SumCommand:
int sum = 0;
foreach (int number in numbers)
{
sum += number;
}
Console.WriteLine($"Сумма значений из массива: {sum}");
break;
case ExitCommand:
isRun = false;
Console.WriteLine("Вы вышли из программы.");
break;
default:
if (string.IsNullOrEmpty(command))
{
Console.WriteLine("Вы не ввели команду.");
break;
}
if (int.TryParse(command, out int parsedNumber))
{
numbers.Add(parsedNumber);
}
else
{
Console.WriteLine("Вы ввели не число.");
}
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment