Last active
July 1, 2020 12:28
-
-
Save lessonstestor/8d771548ca188b0c4d0c8d35d9861645 to your computer and use it in GitHub Desktop.
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.Collections.Generic; | |
namespace ListDynamical | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("\nType 'exit' for - Exit\nType 'sum' for - Get sum of array elements"); | |
Console.ForegroundColor = ConsoleColor.Red; | |
Console.WriteLine("_______________________"); | |
Console.ResetColor(); | |
Console.WriteLine("Input array: "); | |
int sum = 0; | |
List<int> expansionArray = new List<int>(); | |
while (true) | |
{ | |
string inputCommand = Console.ReadLine(); | |
if (inputCommand == "exit") | |
{ | |
break; | |
} | |
else if (inputCommand == "sum") | |
{ | |
Console.WriteLine("Sum of array " + sum); | |
} | |
else | |
{ | |
int inputNumberCommand; | |
if (int.TryParse(inputCommand, out inputNumberCommand)) | |
{ | |
expansionArray.Add(inputNumberCommand); | |
sum += expansionArray[expansionArray.Count - 1]; | |
} | |
else | |
{ | |
Console.WriteLine("Not correct value"); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment