Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.