Skip to content

Instantly share code, notes, and snippets.

@Ana19997
Created October 4, 2021 10:56
Show Gist options
  • Save Ana19997/3604a18ce4beb0804201c04421927557 to your computer and use it in GitHub Desktop.
Save Ana19997/3604a18ce4beb0804201c04421927557 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace сум
{
class Program
{
static void Main(string[] args)
{
string userInput = "";
int[] Data = new int[0];
Console.WriteLine("Введите элемент массива");
while (userInput != "exit")
{
userInput = Console.ReadLine();
switch (userInput)
{
case "sum":
int sum = 0;
Console.WriteLine(String.Format("Сумма элементов = {0}", Data.Sum()));
break;
case "exit":
return;
default:
int result;
if (int.TryParse(userInput, out result))
Data = Data.Concat(new int[] { result }).ToArray();
break;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment