Last active
February 8, 2025 15:35
-
-
Save areaartez51/b72492c12259b708f7438731b77e1dc2 to your computer and use it in GitHub Desktop.
DynamicArray
This file contains 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.Threading; | |
namespace dynamicArray | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
const string CommandSum = "sum"; | |
const string CommandExit = "exit"; | |
int[] defaultStorage = new int[1]; | |
int[] temporaryStorageForSave = defaultStorage; | |
bool isWork = true; | |
string userInput; | |
while (isWork) | |
{ | |
Console.WriteLine("Введите комманду:"); | |
userInput = Console.ReadLine().ToLower(); | |
switch (userInput) | |
{ | |
case CommandSum: | |
Console.Clear(); | |
int totalizer = 0; | |
for (int i = 0; i < defaultStorage.Length; i++) | |
{ | |
totalizer += defaultStorage[i]; | |
} | |
defaultStorage = new int[1]; | |
temporaryStorageForSave = defaultStorage; | |
Console.WriteLine("Сумма записанных чисел: " + totalizer); | |
Thread.Sleep(3000); | |
Console.Clear(); | |
break; | |
case CommandExit: | |
isWork = false; | |
break; | |
default: | |
defaultStorage = temporaryStorageForSave; | |
defaultStorage[defaultStorage.Length-1] = Convert.ToInt32(userInput); | |
Console.Clear(); | |
temporaryStorageForSave = new int[defaultStorage.Length + 1]; | |
Console.Write("Записанные числа: "); | |
for (int i = 0; i < defaultStorage.Length; i++) | |
{ | |
temporaryStorageForSave[i] = defaultStorage[i]; | |
Console.Write(temporaryStorageForSave[i] + " "); | |
} | |
Thread.Sleep(1000); | |
Console.Clear(); | |
break; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment