Advertisement
Vlad_Savitskiy

Dynamic array 2

Jun 28th, 2020
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace CSLight
  6. {
  7.     class Program
  8.     {
  9.         private static void Main()
  10.         {
  11.             List<int> numbers = new List<int>(7);
  12.  
  13.             while (true)
  14.             {
  15.                 Console.Write("Введите число для добавления в список (exit - выход, sum - сумма всех введенных чисел): ");
  16.                 string userInput = Console.ReadLine();
  17.  
  18.                 if (userInput == "exit")
  19.                     break;
  20.                 if (userInput == "sum")
  21.                 {
  22.                     Console.WriteLine($"\nСумма всех числа списка: {numbers.Sum()}\n");
  23.                     continue;
  24.                 }
  25.                 if (int.TryParse(userInput, out int number))
  26.                     numbers.Add(number);
  27.                 else
  28.                     Console.WriteLine("\nНекорректно введено число!\n");
  29.             }
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement