View difference between Paste ID: Pva9XvZ1 and C26sWULh
SHOW: | | - or go back to the newest paste.
1
using System;
2
3
namespace C_sharp_Light
4
{
5
    class Program
6
    {
7
        static void Main(string[] args)
8
        {
9-
            
9+
            int[] array = new int[0];
10
            string command;
11
            bool isOpen = true;
12
13
            while (isOpen)
14
            {
15
                Console.Clear();
16
                Console.WriteLine("Числа в памяти:");
17
                foreach (var number in array)
18
                {
19
                    Console.Write(number + " ");
20
                }
21
                Console.Write("\n\nВведите или число, или команды sum, exit - ");
22
                command = Console.ReadLine();
23
24
                switch (command)
25
                {
26
                    case "sum":
27
                        int sum = 0;
28
                        foreach (var number in array)
29
                        {
30
                            Console.Write(number + "+");
31
                            sum += number;
32
                        }
33
                        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
34
                        Console.Write("=" + sum);
35
                        break;
36
                    case "exit":
37
                        isOpen = false;
38
                        break;
39
                    default:
40
                        int temp = Convert.ToInt32(command);
41
                        int[] tempArray = new int[array.Length + 1];
42
                        for (int i = 0; i < array.Length; i++)
43
                        {
44
                            tempArray[i] = array[i];
45
                        }
46
                        array = tempArray;
47
                        array[array.Length - 1] = temp;
48
                        break;
49
                }
50
                Console.ReadKey();
51
            }
52
        }
53
    }
54
}