kwest87

Untitled

Mar 31st, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp1
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] bag =new int[0];
  15.             bool beOpen = (true);
  16.  
  17.             while (beOpen == true)
  18.             {
  19.                 string command;
  20.                 Console.WriteLine("Введите команду :");
  21.                 command = Console.ReadLine();
  22.  
  23.                 switch (command)
  24.                 {
  25.                     case "exit":
  26.                         beOpen = false;
  27.                         break;
  28.  
  29.                     case "sum":
  30.                         int sum = 0;
  31.  
  32.                         for(int i = 0; i < bag.Length; i++)
  33.                         {
  34.                             sum+=bag[i];
  35.                         }
  36.  
  37.                         Console.WriteLine(sum);
  38.                         break;
  39.  
  40.                     default:
  41.                         int[] tempBag = new int[bag.Length + 1];
  42.  
  43.                         for (int i = 0; i < bag.Length; i++)
  44.                         {
  45.                             tempBag[i] = bag[i];
  46.                         }
  47.  
  48.                         tempBag[tempBag.Length -1] = Convert.ToByte(command);
  49.                         bag = tempBag;
  50.                         continue;
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
  56. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment