Last active
January 12, 2026 12:24
-
-
Save VladimirYus/4e6bb462663df1d26e7fd94fdf9b247a to your computer and use it in GitHub Desktop.
DynamicArray
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| namespace DynamicArray | |
| { | |
| internal class Program | |
| { | |
| static void Main(string[] args) | |
| { | |
| const string CommandSum = "sum"; | |
| const string CommandExit = "exit"; | |
| const string CommandClear = "clear"; | |
| List<int> numbers = new List<int>(); | |
| string inputUser; | |
| bool isWork = true; | |
| while (isWork) | |
| { | |
| Console.Write($"Введите целое число или команду:\n{CommandSum} для суммы\n{CommandClear} для очистки консоли\n{CommandExit} для выхода\n"); | |
| inputUser = Console.ReadLine().ToLower(); | |
| switch (inputUser) | |
| { | |
| case CommandSum: | |
| SumNumbers(numbers); | |
| break; | |
| case CommandClear: | |
| numbers.Clear(); | |
| Console.Clear(); | |
| break; | |
| case CommandExit: | |
| isWork = false; | |
| Console.WriteLine("Выход из программы."); | |
| break; | |
| default: | |
| int userInputNumber; | |
| if (int.TryParse(inputUser, out userInputNumber)) | |
| { | |
| numbers.Add(userInputNumber); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Некорректный ввод. Пожалуйста, введите число или команду."); | |
| } | |
| break; | |
| } | |
| } | |
| } | |
| static void SumNumbers(List<int> numbers) | |
| { | |
| int sumAllNumbers = 0; | |
| for (int i = 0; i < numbers.Count; i++) | |
| { | |
| sumAllNumbers += numbers[i]; | |
| } | |
| Console.WriteLine("Сумма всех введенных чисел: " + sumAllNumbers); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment