Skip to content

Instantly share code, notes, and snippets.

@lessonstestor
Last active July 1, 2020 12:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lessonstestor/8d771548ca188b0c4d0c8d35d9861645 to your computer and use it in GitHub Desktop.
Save lessonstestor/8d771548ca188b0c4d0c8d35d9861645 to your computer and use it in GitHub Desktop.
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